alpaca_basic.js 9.56 KB
Newer Older
Percy Quispe committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
/* ------------------------------------------------------------------------------
*
*  # Alpaca - Basic inputs
*
*  Specific JS code additions for alpaca_basic.html page
*
*  Version: 1.0
*  Latest update: Mar 10, 2016
*
* ---------------------------------------------------------------------------- */

$(function() {


    // Text input
    // ------------------------------

    // Basic example
    $("#alpaca-basic").alpaca({
        "data": "I Love Alpaca Ice Cream!",
        "options": {
            "focus": false
        }
    });


    // Display only view
    $("#alpaca-static").alpaca({
        "data": "I Love Alpaca Ice Cream!",
        "schema": {
            "type": "string"
        },
        "view": "bootstrap-display"
    });


    // Input field label
    $("#alpaca-input-label").alpaca({
        "data": "I Love Alpaca Ice Cream!",
        "options": {
            "label": "Input label",
            "focus": false
        }
    });


    // Static input label
    $("#alpaca-static-label").alpaca({
        "data": "I Love Alpaca Ice Cream!",
        "schema": {
            "type": "string"
        },
        "options": {
            "label": "Input label"
        },
        "view": "bootstrap-display"
    });


    // Validation
    $("#alpaca-validation").alpaca({
        "data": "Mint",
        "schema": {
            "minLength": 3,
            "maxLength": 5
        },
        "options": {
            "label": "Ice Cream",
            "helper": "Your favorite ice cream?",
            "size": 30,
            "focus": false
        }
    });


    // Validation with predefined value
    $("#alpaca-validation-predefined").alpaca({
        "data": "Mint Chocolate",
        "schema": {
            "minLength": 3,
            "maxLength": 5
        },
        "options": {
            "label": "Ice Cream",
            "helper": "Please tell us the kind of ice cream you love most!",
            "size": 30,
            "focus": false,
            "placeholder": "Enter an ice cream flavor"
        }
    });


    // Disallow empty spaces
    $("#alpaca-disallow-empty").alpaca({
        "schema": {
            "type": "string"
        },
        "options": {
            "type": "lowercase",
            "label": "User Name",
            "disallowEmptySpaces": true,
            "helper": "Type something with empty space",
            "focus": false
        }
    });


    // Disallow values
    $("#alpaca-disallow-values").alpaca({
        "data": "Mickey Mantle",
        "schema": {
            "type": "string",
            "disallow": ["Mickey Mantle", "Mickey"]
        },
        "options": {
            "label": "Name",
            "focus": false
        }
    });


    // Typeahead integration
    $("#alpaca-typeahead").alpaca({
        "schema": {
            "type": "string"
        },
        "options": {
            "type": "text",
            "label": "Company Name",
            "helper": "Select the name of a computing company",
            "placeholder": "Enter 'a'",
            "focus": false,
            "typeahead": {
                "config": {
                    "autoselect": true,
                    "highlight": true,
                    "hint": true,
                    "minLength": 1
                },
                "datasets": {
                    "type": "local",
                    "source": function(query) {
                        var companies = ["Google", "Amazon", "Microsoft", "Apple", "Spotify", "Alpaca", "Another company", "Facebook"];
                        var results = [];
                        for (var i = 0; i < companies.length; i++) {
                            var add = true;
                            if (query) {
                                add = (companies[i].indexOf(query) === 0);
                            }
                            if (add) {
                                results.push({
                                    "value": companies[i]
                                });
                            }
                        }
                        return results;
                    }
                }
            }
        }
    });


    // Maxlength integration
    $("#alpaca-maxlength").alpaca({
        "schema": {
            "type": "string",
            "minLength": 3,
            "maxLength": 25
        },
        "options": {
            "type": "text",
            "label": "What is your name?",
            "constrainMaxLength": true,
            "constrainMinLength": true,
            "showMaxLengthIndicator": true,
            "focus": false
        },
        "data": "Jackie Robinson"
    });



    // Textareas
    // ------------------------------

    // Basic textarea
    $("#alpaca-textarea").alpaca({
        "data": "Ice cream or ice-cream is a frozen dessert usually made from dairy products, such as milk and cream, and often combined with fruits or other ingredients and flavours.",
        "options": {
            "type": "textarea",
            "label": "Receipt",
            "helper": "Receipt for Best Homemade Ice Cream",
            "rows": 4,
            "cols": 80,
            "focus": false
        }
    });


    // With placeholder
    $("#alpaca-textarea-placeholder").alpaca({
        "options": {
            "type": "textarea",
            "label": "Receipt",
            "helper": "Receipt for Best Homemade Ice Cream",
            "placeholder": "Enter your favorite ice cream here...",
            "rows": 4,
            "cols": 80,
            "focus": false
        }
    });


    // Display mode
    $("#alpaca-textarea-static").alpaca({
        "data": "Ice cream or ice-cream is a frozen dessert usually made from dairy products, such as milk and cream, and often combined with fruits or other ingredients and flavours.",
        "options": {
            "type": "textarea",
            "label": "Receipt",
            "rows": 6,
            "cols": 80,
            "focus": false
        },
        "view": "bootstrap-display"
    });


    // Single field render
    $("#alpaca-textarea-override").alpaca({
        "data": "My name is Dr. Jacobian and I am a neuroscientist from the Cornell University.  I've perfected a DNA transcription process which makes it possible for the first time to use DNA nucleotides to store pedabytes of information in real-time.",
        "schema": {
            "type": "string"
        },
        "options": {
            "type": "textarea",
            "label": "Tell us about yourself",
            "view": "bootstrap-display"
        }
    });



    // Selects
    // ------------------------------

    // Basic select
    $("#alpaca-select").alpaca({
        "data": "coffee",
        "schema": {
            "enum": ["vanilla", "chocolate", "coffee", "strawberry", "mint"]
        },
        "options": {
            "label": "Ice cream",
            "helper": "What flavor of ice cream do you prefer?",
            "focus": false
        }
    });


    // External data source
    $("#alpaca-select-external").alpaca({
        "options": {
            "label": "Ice cream",
            "helper": "Guess my favorite ice cream?",
            "type": "select",
            "focus": false,
            "dataSource": "../default/assets/demo_data/alpaca/selects.json"
        }
    });


    // Select2 select
    $("#alpaca-select2").alpaca({
        "data": "coffee",
        "schema": {
            "enum": ["vanilla", "chocolate", "coffee", "strawberry", "mint"]
        },
        "options": {
            "label": "Ice cream",
            "helper": "What flavor of ice cream do you prefer?",
            "id": "select2-basic",
            "focus": false
        },
        "postRender": function(control) {
            $('#select2-basic').select2({
                minimumResultsForSearch: Infinity
            });
        }
    });


    // Select2 select with search
    $("#alpaca-select2-search").alpaca({
        "data": "coffee",
        "schema": {
            "enum": ["vanilla", "chocolate", "coffee", "strawberry", "mint"]
        },
        "options": {
            "label": "Ice cream",
            "helper": "What flavor of ice cream do you prefer?",
            "id": "select2-search",
            "focus": false
        },
        "postRender": function(control) {
            $('#select2-search').select2();
        }
    });


    // Multiselect
    $("#alpaca-multiselect").alpaca({
        "data": ["Vanilla", "Chocolate"],
        "schema": {
            "type": "array",
            "items": {
                "title": "Ice Cream",
                "type": "string",
                "enum": ["Vanilla", "Chocolate", "Strawberry", "Mint"],
                "minItems": 2,
                "maxItems": 3
            }
        },
        "options": {
            "label": "Ice cream",
            "helper": "Guess my favorite ice cream?",
            "type": "select",
            "size": 5,
            "id": "multiselect",
            "focus": false
        },
        "postRender": function(control) {
            $("#multiselect").parent().find("input[type=checkbox]").uniform();
        }
    });


    // Multiselect with remote data
    $("#alpaca-multiselect-remote").alpaca({
        "options": {
            "label": "Select your favorite flavor of ice cream",
            "type": "select",
            "multiple": true,
            "helper": "Guess my favorite ice cream?",
            "size": 3,
            "focus": false,
            "id": "multiselect-remote",
            "dataSource": "../default/assets/demo_data/alpaca/selects.json"
        },
        "postRender": function(control) {
            $("#multiselect-remote").parent().find("input[type=checkbox]").uniform();
        }
    });

});