Fork me on GitHub

Example: Basic number creation

How to create a number.

Basic NumberField creation

Use the following code to create a basic inputEx NumberField.

Supported format

Everything accepted by parseFloat is valid.

Min & Max

Check a minimum or a maximum value

HTML

<div id="field-container"></div>

JavaScript

Implementation

YUI().use('inputex-number',  function(Y) {

    // Example 1
    var field = new Y.inputEx.NumberField({
        parentEl: 'container1',
        showMsg: true,
        value: 0.03
    });

    // Example 2
    var field2 = new Y.inputEx.NumberField({
        parentEl: 'container2',
        showMsg: true,
        value: '03e-2',
        required:true,
        placeholder: "Float numbers accepted"
    });

    // Example 3
    field3 = new Y.inputEx.NumberField({
        parentEl: 'container3',
        showMsg: true,
        min: -15,
        max: '1e3',
        placeholder: "Numbers between -15 and 1e3 (1000) only",
        size: 40
    });


    // Add "getValue" buttons
    Y.Array.each([field, field2, field3], function (f) {

        var container = Y.one(f.getEl()).ancestor('.demoContainer');

        Y.Node.create('<button>getValue</button>').
               appendTo(container).
               on('click', function() { alert(f.getValue()); });

    });

});