Input Widget

Description:
Adding multiple inputs to your webpage in various types.

Quick navigation Examples

Options

Methods

Events

Options

accept

Type:
Array
Default value:
[]

The accept array contains the file types which are accepted by the file upload field.

Code examples
Initialize the input widget with the accept option specified, using object in constructor
$A.newInput({
    type:'file',
    accept: ['.csv', '.rar', '.zip', '.tar', '.gz']
}).draw();
            
Initialize the input widget with the accept option specified, using method chaining
$A.newInput().accept(['.csv', '.rar', '.zip', '.tar', '.gz']).draw();
            

Get or set the accept option, after initialization
var input = $A.newInput().draw();
//Setter
input.accept(['.csv', '.rar', '.zip', '.tar', '.gz']); //returns input

//Getter
console.log(input.accept()); //returns value of accept
            

breakInput

Type:
Boolean
Default value:
false

If true the input field will appear in a new row, below the label.

Code examples
Initialize the input widget with the breakInput option specified, using object in constructor
$A.newInput({
    label: 'title',
    breakInput: true
}).draw();
            
Initialize the input widget with the breakInput option specified, using method chaining
$A.newInput().breakInput(true).label('title').draw();
            

Get or set the breakInput option, after initialization
var input = $A.newInput().label('title').draw();
//Setter
input.breakInput(true); //returns input

//Getter
console.log(input.breakInput()); //returns value of breakInput
            

checked

Type:
Boolean
Default value:
false

Shows if the radio button or checkbox input is checked.

Code examples
Initialize the input widget with the checked option specified, using object in constructor
$A.newInput({
    type: 'radio',
    checked: true
}).draw();
            
Initialize the input widget with the checked option specified, using method chaining
$A.newInput({type: 'radio'}).checked(true).draw();
            

Get or set the checked option, after initialization
var input = $A.newInput({type: 'radio'}).draw();
//Setter
input.checked(true); //returns input

//Getter
console.log(input.checked()); //returns value of checked
            

height

Type:
Number|String
Default value:
"auto"

Setting the height of the input field.

Code examples
Initialize the input widget with the height option specified, using object in constructor
$A.newInput({
    height:"100px"
}).draw();
            
Initialize the input widget with the height option specified, using method chaining
$A.newInput().height("100px").draw();
            

Get or set the height option, after initialization
var input = $A.newInput().draw();
//Setter
input.height(100); //returns input

//Getter
console.log(input.height()); //returns the height
            

help

Type:
String
Default value:
""

If set, an icon appears next to the particular input showing a hint when mouse is hovered.

Code examples
Initialize the input widget with the help option specified, using object in constructor
$A.newInput({
    help: "Tell the user what to do",
}).draw();
            
Initialize the input widget with the help option specified, using method chaining
$A.newInput().help("Tell the user what to do").draw();
            

Get or set the help option, after initialization
var input = $A.newInput().draw();
//Setter
input.help("Tell the user what to do"); //returns input

//Getter
console.log(input.help()); //returns the help string
            

items

This option is an alias for the options method.

label

Type:
String
Default value:
true

If set, a label appears beneath the input.

Code examples
Initialize the input widget with the label option specified, using object in constructor
$A.newInput({
    label: 'Name:'
}).draw();
            
Initialize the input widget with the label option specified, using method chaining
$A.newInput().label('Name:').draw();
            

Get or set the label option, after initialization
var input = $A.newInput().draw();
//Setter
input.label('Name:'); //returns input

//Getter
console.log(input.label()); //returns value of label
            

labelPosition

Type:
String
Default value:
'left'

Setting the position of the label.
Allowed values: 'left', 'right'

Code examples
Initialize the input widget with the labelPosition option specified, using object in constructor
$A.newInput({
    label: 'Name:',
    labelPosition: 'right'
}).draw();
            
Initialize the input widget with the labelPosition option specified, using method chaining
$A.newInput().label('Name:').labelPosition('right').draw();
            

Get or set the labelPosition option, after initialization
var input = $A.newInput().label('Name:').draw();
//Setter
input.labelPosition('right'); //returns input

//Getter
console.log(input.labelPosition()); //returns value of labelPosition
            

labelWidth

Type:
Number|String
Default value:
''

Setting the width of the label.

Code examples
Initialize the input widget with the labelWidth option specified, using object in constructor
$A.newInput({
    label: 'Name:',
    labelWidth: '100'
}).draw();
            
Initialize the input widget with the labelWidth option specified, using method chaining
$A.newInput().label('Name:').labelWidth(100).draw();
            

Get or set the labelWidth option, after initialization
var input = $A.newInput().label('Name:').draw();
//Setter
input.labelWidth('100px'); //returns input

//Getter
console.log(input.labelWidth()); //returns value of labelWidth
            

multiple

Type:
Boolean
Default value:
false

This option can modify the function of a select input element.
If true: the select element will be set so, that you can select multiple options.
If false: the select element will be set so, that you can select only one option.

Code examples
Initialize the input widget with the multiple option specified, using object in constructor
$A.newInput({
    type: 'select',
    options: [
        [0, '--- Nothing ---'],
        [12, 'First Segment'],
        [15, 'Second Segment']
    ],
    multiple: true,
}).draw();
            
Initialize the input widget with the multiple option specified, using method chaining
$A.newInput().type('select').multiple(true).options([[0, '--- Nothing ---'],[12, 'First Segment'],[15, 'Second Segment']]).draw();
            

Get or set the multiple option, after initialization
var input = $A.newInput({type: 'select'}).options([[0, '--- Nothing ---'],[12, 'First Segment'],[15, 'Second Segment']]).draw();
//Setter
input.multiple(true); //returns input

//Getter
console.log(input.multiple()); //returns value of multiple
            

multiselect

Type:
Boolean
Default value:
true

By setting it true you can apply the jQuery UI Multiselect Widget on your select fields.
Else the default HTML skin will be applied on the fields.

Code examples
Initialize the input widget with the multiselect option specified, using object in constructor
$A.newInput({
    type: 'select',
    options: [
        [0, '--- Nothing ---'],
        [12, 'First Segment'],
        [15, 'Second Segment']
    ],
    multiselect: true
}).draw();
            
Initialize the input widget with the multiselect option specified, using method chaining
$A.newInput().multiselect(true).draw();
            

Get or set the multiselect option, after initialization
var input = $A.newInput().draw();
//Setter
input.multiselect(true); //returns input

//Getter
console.log(input.multiselect()); //returns value of multiselect
            

name

Type:
String
Default value:
""

Sets the name attribute of the particular input element in the DOM.

Code examples
Initialize the input widget with the name option specified, using object in constructor
$A.newInput({
    name: 'address'
}).draw();
            
Initialize the input widget with the name option specified, using method chaining
$A.newInput().name('address').draw();
            

Get or set the name option, after initialization
var input = $A.newInput().draw();
//Setter
input.name('address'); //returns input

//Getter
console.log(input.name()); //returns value of name
            

needModify

Type:
Boolean
Default value:
false

This option is in close connection with the form module.
If needModify is set, the particular input won't be serialized and sent in case it's value is the same as its previous value.

Code examples
Initialize the input widget with the needModify option specified, using object in constructor
$A.newInput({
    needModify: true
}).draw();
            
Initialize the input widget with the needModify option specified, using method chaining
$A.newInput().needModify(true).draw();
            

Get or set the needModify option, after initialization
var input = $A.newInput().draw();
//Setter
input.needModify(true); //returns input

//Getter
console.log(input.needModify()); //returns value of needModify
            

newRow

Type:
Boolean
Default value:
true

If true the input element (including the label) will appear in a new row. Then no other elements can be inserted in that row.
If false the input element (including the label) will appear in the same row, next to the previous element.

Code examples
Initialize the input widget with the newRow option specified, using object in constructor
$A.newInput({
    newRow: false
}).draw();
            
Initialize the input widget with the newRow option specified, using method chaining
$A.newInput().newRow(false).draw();
            

Get or set the newRow option, after initialization
var input = $A.newInput().draw();
//Setter
input.newRow(false); //returns input

//Getter
console.log(input.newRow()); //returns value of newRow
            

options

Type:
Array | Object
Default value:
[]

The array or object containing the options which can be selected when using a select or multiselect as input.
If previously defined, setter will replace the old array with the one given as argument. To add further options use the addItem or addOption methods.
If using an array, you can set which option should be selected by default. (Shown in example)

Code examples
Initialize the input widget with the options option specified, using object in constructor
//Using object as argument:
$A.newInput({
    type: 'select',
    options:{
        1: 'option1',
        two: 2,
        three: 'option three'
    }
}).draw();

//Using an array of arrays as argument:
$A.newInput({
    type: 'select',
    options:[
        [1, 'option1'],
        ['two', 2, true], //this element will be selected by default, as we gave 'true' a third parameter of the option.
        ['three', 'option three']
    ]
}).draw();
            
Initialize the input widget with the options option specified, using method chaining
$A.newInput({type: 'select'}).options([[1, 'option1'], ['two', 2, true], ['three', 'option three']]).draw();
            

Get or set the options option, after initialization
var input = $A.newInput({type: 'select'}).draw();
//Setter
input.options([[1, 'option1'], ['two', 2, true], ['three', 'option three']]); //returns input

//Getter
console.log(input.options()); //returns the options array
            

placeholder

Type:
String
Default value:
""

Use this option on input fields to write predefined text which can give the user some hints.
Actually sets the placeholder attribute of an input field.

Code examples
Initialize the input widget with the placeholder option specified, using object in constructor
$A.newInput({
    type: 'text',
    placeholder: 'Name'
}).draw();
            
Initialize the input widget with the placeholder option specified, using method chaining
$A.newInput({type: 'text'}).placeholder('Name').draw();
            

Get or set the placeholder option, after initialization
var input = $A.newInput({type: 'text'}).draw();
//Setter
input.placeholder('Name'); //returns input

//Getter
console.log(input.placeholder()); //returns the value of placeholder
            

readonly

Type:
Boolean
Default value:
false

Set this option true to make an input read-only.

Code examples
Initialize the input widget with the readonly option specified, using object in constructor
$A.newInput({
    readonly: true
}).draw();
            
Initialize the input widget with the readonly option specified, using method chaining
$A.newInput().readonly(true).draw();
            

Get or set the readonly option, after initialization
var input = $A.newInput().draw();
//Setter
input.readonly(true); //returns input

//Getter
console.log(input.readonly()); //returns value of readonly

            

type

Type:
String
Default value:
'text'

Use this option to set the type attribute of the input element.

Code examples
Initialize the input widget with the type option specified, using object in constructor
$A.newInput({
    type: 'textarea'
}).draw();
            
Initialize the input widget with the type option specified, using method chaining
$A.newInput().type('textarea').draw();
            

Get or set the type option, after initialization
var input = $A.newInput().draw();
//Setter
input.type('textarea'); //returns input

//Getter
console.log(input.type()); //returns value of type
            

value

Type:
String
Default value:

Use this option to set the value of any input.

Code examples
Initialize the input widget with the value option specified, using object in constructor
$A.newInput({
    type: 'text',
    value: 'Default text'
}).draw();
            
Initialize the input widget with the value option specified, using method chaining
$A.newInput({type: 'text'}).value('Default text').draw();
            

Get or set the value option, after initialization
var input = $A.newInput().draw();
//Setter
input.value('Default text'); //returns input

//Getter
console.log(input.value()); //returns value

            

validator

Type:
Validator | String | Object
Default value:
$A.newValidator()

AutomizyJS has bulit-in validators for various types of input, using this option you can set which one you would like to use.
For further details check the Validator Module documentation.

Code examples
Initialize the input widget with the validator option specified, using object in constructor

$A.newInput({
    validator: 'email'
}).draw();
            
Initialize the input widget with the validator option specified, using method chaining
$A.newInput().validator('email').draw();
            

Get or set the validator option, after initialization
var input = $A.newInput().draw();
//Setter:
input.validator('email'); //returns input

//Getter
console.log(input.validator()); //returns validator

            

width

Type:
Number
Default value:
600

The width of the input field in pixels.

Code examples
Initialize the input widget with the width option specified, using object in constructor
$A.newInput({
    width: 600
}).draw();                  
            
Initialize the input widget with the width option specified, using method chaining
$A.newInput().width(600).draw();
            
Get or set the width option, after initialization
var input = $A.newInput().draw();
//Setter
input.width(600);  //returns input

//Getter
console.log(input.width()); //returns value of width
            

Methods

addItem(key, value)

Returns:
Input

Use this method to add a new option to your select or multiselect input.
The new option will be added to the end of the options array.

  • key
    Type: String | Number
    The key of the new option.
  • value
    Type: String | Number
    The value of the new option.
Code examples
var input=$A.newInput({type: 'select'}).draw();
input.addItem(1, 'First option');
            

addItemBefore(key, value)

Returns:
Input

Use this method to add a new option to your select or multiselect input.
The new option will be added to the beginning of the options array.

  • key
    Type: String | Number
    The key of the new option.
  • value
    Type: String | Number
    The value of the new option.
Code examples
var input=$A.newInput({type: 'select'}).addItem(2, 'Second option').draw();
input.addItemBefore(1, 'First option');
            

addItems(arr, before)

Returns:
Input

Use this method to add an array of new options to your select or multiselect input.
The new options will be added to the beginning or to the end of the options array depending on the value of the before parameter.

  • arr
    Type: Array | Object
    The array or object of new options.
    If using an array, you can set which option should be selected by default. (Shown in example)
  • before
    Type: Boolean
    If true the new options will be added to the beginning of the original options array.
    If false the new options will be added to the end of the original options array.
Code examples
var input=$A.newInput({type: 'select'}).draw();
//Using an object as argument:
input.addItems({
    1: 'option1',
    two: 2,
    three: 'option three'
});  //no second parameter given -> These options will be added to the end of the original 'options' array.

//Using an array of arrays as argument:
input.addItems([
    [1, 'option1'],
    ['two', 2, true], //this element will be selected by default, as we gave 'true' a third parameter of the option.
    ['three', 'option three']
], true); //'true' parameter given -> These options will be inserted before the first element of the original 'options' array.
            

datepicker()

Returns:
Input

Use this method to apply a datepicker on the particular input.
Please note that jQuery UI plugin is needed for this feature.

Code examples
var input=$A.newInput().draw();
input.datepicker();
            

datetimepicker()

Returns:
Input

Use this method to apply a datetimepicker on the particular input.
Please note that jQuery UI plugin is needed for this feature.

Code examples
var input=$A.newInput().draw();
input.datetimepicker();
            

disable()

Returns:
Input

Use this to disable the particular input element.
Disabled inputs cannot be selected, edited or copied.

Code examples
var input=$A.newInput().draw();
input.disable();
            

enable()

Returns:
Input

Use this to enable the particular input element.

Code examples
var input=$A.newInput().disable().draw();
setTimeout(function(){
    input.enable();
},1000);
            

errorBox()

Returns:
jQuery

Returns the JQuery object that represents the error box of the particular input element.
errorBox is the element which appears when the user types invalid value in an input field.

Code examples
var input=$A.newInput({
    label: 'Email address:',
    value: 'Type here an invalid email address!', //invalid email address given
    validator: 'email'
}).draw().validate();
input.errorBox(); //returns [<span class="automizy-input-box-error">Invalid email address</span>]
            

focus()

Returns:
Input

Use this option to set the focus of the given input.

Code examples
var input=$A.newInput({
    label: 'Email address:',
}).draw()
setTimeout( function(){
    input.focus();
},1000);
            

input()

Returns:
jQuery

Returns the JQuery object that represents the particular input element.

Code examples
var input=$A.newInput({name: 'asd', type: 'textarea', id:'txtarea01'}).draw();
console.log(input.input()); //returns [<textarea id="txtarea01" name="asd" style="display: inline-block;"></textarea>]
            

timepicker()

Returns:
Input

Use this method to apply a timepicker on the particular input.
Please note that jQuery UI plugin is needed for this feature.

Code examples
var input=$A.newInput().draw();
input.timepicker();
            

val()

Sets or gets the value of any input element. Works the same as the jQuery .val() function.

Code examples
var input = $A.newInput().draw();
//Setter
input.val('Default text'); //returns input

//Getter
console.log(input.val()); //returns value
            

validate(func)

Returns:
Boolean | Input

Use this method to run the set validator to validate the particular input field.
If invoked without parameter the function returns true or false depending on the result of validation.
If invoked with parameter returns with the particular input module.

  • func
    Type: function
    The function which will be invoked after validation is over.
Code examples
var input=$A.newInput({label: 'Age:', value: 14, validator: {num: true, min: 18, max: 130}}).draw();
//Invoke without parameter
input.validate(); //returns result of validation (true|false)

//Invoke with parameter
input.validate(function(){
    alert('Validation over!');
});
            

Events

change(event)

Returns:
Input

By setting this event you can give a function which will be invoked after any changes on the Input widget.

  • event
    Type: function
    The event which will be triggered on the change of the Input widget.
Code examples
var input=$A.newInput({label: 'Type something here, then click out of the input field!'}).draw();
input.change(function (){
    alert('Input widget changed!');
})
            

check()

Returns:
Input

Sets the checked property of particular checkbox or radio button true.

Code examples
var input=$A.newInput({type: 'checkbox'}).draw();
setTimeout(function(){
    input.check();
},1000);
            

click(event)

Returns:
Input

You can set the event you want to be triggered when clicking on the particular input.

  • event
    Type: function
    The event to be triggered
Code examples
var input=$A.newInput().label('Click in the input field!').draw();
input.click(function(){
    alert('Clicked!');
})          
            

enter(event)

Returns:
Input

You can set the event you want to be triggered when clicking on the particular input.

  • event
    Type: function
    The event to be triggered
Code examples
var input=$A.newInput().label('Click in the input field, then press enter!').draw();
input.enter(function(){
    alert('Pressed enter!');
})          
            

uncheck()

Returns:
Input

Sets the checked property of particular checkbox or radio button false.

Code examples
var input=$A.newInput({type: 'checkbox'}).draw().check();
setTimeout(function (){
    input.uncheck()
    },1000);
            

Examples

A simple module


            

Demo: