How to use the can.type.maybeConvert function in can

To help you get started, we’ve selected a few can examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github canjs / canjs / demos / forms / extended-make-model-year.html View on Github external
{{/ for }}
            
        {{ else }}
            <select disabled=""><option>Years</option></select>
        {{/ if }}

        <div>
            {{# for(vehicle of this.vehicles) }}
                <h2>{{ vehicle.name }}</h2>
                <img width="200px">
            {{/ for }}
        </div>
    `;

    static props = {
        makeId: type.maybeConvert(String),
        makes: {
            get() {
                return ajax({
                    type: "GET",
                    url: "/makes"
                }).then(resp =&gt; resp.data);
            }
        },
        modelId: {
            type: String,
            value({ lastSet, listenTo, resolve }) {
                listenTo(lastSet, resolve);

                listenTo("makeId", () =&gt; resolve(""));
            }
        },
github canjs / canjs / demos / forms / extended-pizza-example.html View on Github external
<div>
            <p>Select {{ this.listName }}:</p>

            {{# for(option of this.options) }}
                <label>
                    {{ option }}
                    <input type="checkbox">
                </label>
            {{/ for }}
        </div>
    `;

    static props = {
        listName: { type: type.maybeConvert(String), default: "many" },
        options: type.maybeConvert(ObservableArray),
        update: Function
    };
};

customElements.define("select-many", SelectMany);

class MeatPicker extends StacheElement {
    static view = `
        {{ let showOptions=null }}
        <div>
            <label>
                Vegetarian
                </label></div>
github canjs / canjs / demos / forms / extended-pizza-example.html View on Github external
<div>
            <p>Select {{ this.listName }}:</p>

            <select>
                {{# for(option of this.options) }}
                    <option>{{ option }}</option>
                {{/ for }}
            </select>
        </div>
    `;

    static props = {
        listName: { type: type.maybeConvert(String), default: "one" },
        options: type.maybeConvert(ObservableArray),
        default: type.maybeConvert(String),
        update: Function
    };
};

customElements.define("select-one", SelectOne);

class SelectMany extends StacheElement {
    static view = `
        <div>
            <p>Select {{ this.listName }}:</p>

            {{# for(option of this.options) }}
                <label>
                    {{ option }}
                    </label></div>
github canjs / canjs / demos / can-connect / real-time.html View on Github external
static get props() {
        return {
            id: type.maybeConvert(Number),
            name: type.maybeConvert(String),
            complete: type.maybeConvert(Boolean)
        };
    }
}
github canjs / canjs / demos / forms / elements-number.html View on Github external
<label>
            Number (type: "any"):
            <input type="number">
        </label>
        <p>
            Number (type: "any"):
             {{# eq(typeof(this.favoriteNumberAnyType), "string" }}
                 "{{ this.favoriteNumberAnyType }}"
             {{ else }}
                 {{ this.favoriteNumberAnyType }}
             {{/ eq }}
        </p>
    `;

    static props = {
        favoriteNumber: type.maybeConvert(Number),
        favoriteNumberAnyType: type.Any
    };

    typeof(val) {
        return typeof val;
    }
};
customElements.define("number-inputs", NumberInputs);

github canjs / canjs / demos / forms / elements-select-multiple.html View on Github external
<option>Green peppers</option>
                <option>Pineapple</option>
                <option>Spinach</option>
            
        

        <p>
            Selected toppings:
            {{# for( topping of this.toppings) }}
                {{ topping }}
            {{/ for }}
        </p>
    `;

    static props = {
        toppings: type.maybeConvert(ObservableArray)
    };
};
customElements.define("pizza-toppings-picker", PizzaToppingsPicker);

github canjs / canjs / demos / forms / elements-select-selected-to-index.html View on Github external
<option>9</option>
                <option>10</option>
                <option>11</option>
            
        

        <p>Selected index: {{ this.selectedIndex }}</p>

        <label>
            Selected Month:
            <input>
        </label>
    `;

    static props = {
        selectedIndex: type.maybeConvert(Number),

        months: {
            get default() {
                return [
                    "Jan",
                    "Feb",
                    "March",
                    "April",
                    "May",
                    "June",
                    "July",
                    "Aug",
                    "Sept",
                    "Oct",
                    "Nov",
                    "Dec"
github canjs / canjs / demos / can-connect / real-time.html View on Github external
static get items() {
        return type.maybeConvert(Todo);
    }
}
github canjs / canjs / demos / can-connect / fall-through-cache.html View on Github external
static get props() {
        return {
            id: {type: type.maybeConvert(Number), identity: true},
            name: type.maybeConvert(String),
            complete: type.maybeConvert(Boolean)
        };
    }
}
github canjs / canjs / demos / forms / elements-checkbox-boolean-to-inlist.html View on Github external
static view = `
        {{# for(number of this.availableNumbers }}
        <label>
            <input type="checkbox">
                checked:bind="boolean-to-inList({{ number }}, numbers)"
        </label>
        {{/ for }}
        <p>
            selected numbers: {{# for(number of this.selectedNumbers) }}{{ number }} {{/ for }}
        </p>
    `;

    static props = {
        availableNumbers: {
            type: type.maybeConvert(ObservableArray),

            get default() {
                return [ "one", "two", "three" ];
            }
        },
        selectedNumbers: {
            type: type.maybeConvert(ObservableArray),

            get default() {
                return [];
            }
        }
    };
};
customElements.define("checkbox-inlist", CheckboxInlist);