inputEx - ListField Usage

Basic ListField creation

Use the following code to create a basic inputEx ListField.

1var field = new inputEx.ListField({ 
2    name: 'websiteUrl',  
3    listLabel: 'Websites'
4    elementType: {type: 'url'}, 
5    value: ['http://www.neyric.com''http://www.ajaxian.com''http://www.google.com''http://www.yahoo.com'],  
6    parentEl: 'container1' 
7}); 
8var button = inputEx.cn('button'nullnull'getValue()'); 
9YAHOO.util.Dom.get('container1').appendChild(button);  
10YAHOO.util.Event.addListener(button, 'click'function() { alert( YAHOO.lang.JSON.stringify(field.getValue())); });   
11var button2 = inputEx.cn('button'nullnull'setValue()'); 
12YAHOO.util.Dom.get('container1').appendChild(button2);  
13YAHOO.util.Event.addListener(button2, 'click'function() { 
14    field.setValue(['http://www.sncf.com'
15                                    'http://www.clicrdv.com'
16                                    'http://www.neyric.com'
17                                    'http://javascript.neyric.com/wireit']);             
18}); 
19var button3 = inputEx.cn('button'nullnull'Clear'); 
20YAHOO.util.Dom.get('container1').appendChild(button3);  
21YAHOO.util.Event.addListener(button3, 'click'function() { 
22    field.setValue([]); 
23}); 
view plain | print | ?

Sortable list

Example for the sortable ListField

1var field2 = new inputEx.ListField({ 
2    listLabel: 'Reorder example'
3    elementType: {type: 'string'}, 
4    value: ['one''two''three''four'],  
5    parentEl: 'container2'
6    sortable: true 
7}); 
8var buttonGetValue = inputEx.cn('button'nullnull'getValue()'); 
9YAHOO.util.Dom.get('container2').appendChild(buttonGetValue);  
10YAHOO.util.Event.addListener(buttonGetValue, 'click'function() {  
11    alert( YAHOO.lang.JSON.stringify(field2.getValue()));  
12}); 
view plain | print | ?

Updated event

How to listen to the updated event :

Log :
1var field3 = new inputEx.ListField({parentEl: 'container3', value: ["one""two""three""four"], sortable: true }); 
2var logDiv = inputEx.cn('div'nullnull"Log :"); 
3YAHOO.util.Dom.get('container3').appendChild(logDiv); 
4field3.updatedEvt.subscribe(function(e,params) { 
5    var value = params[0]; 
6    logDiv.innerHTML += "Updated at "+(new Date())+" with value "+YAHOO.lang.JSON.stringify(value); 
7}); 
view plain | print | ?

Use buttons instead of links

Use buttons :

1new inputEx.ListField({ 
2    listLabel: 'Websites'
3    elementType: { 
4        type: 'select',  
5        choices:  ['http://www.neyric.com''http://www.ajaxian.com''http://www.google.com''http://www.yahoo.com''http://javascript.neyric.com/blog''http://javascript.neyric.com/wireit''http://neyric.github.com/inputex'
6    }, 
7    value: ['http://www.neyric.com''http://www.ajaxian.com''http://www.google.com''http://www.yahoo.com'],  
8    parentEl: 'container4'
9    useButtons: true // set to true to display buttons instead of links 
10}); 
view plain | print | ?

Set maximum/minimum number of items

Use the maxItems and minItems options :

1new inputEx.ListField({ 
2    listLabel: 'Websites'
3    maxItems: 4, 
4    minItems: 1, 
5    elementType: { 
6        type: 'select'
7        choices:  ['http://www.neyric.com''http://www.ajaxian.com''http://www.google.com''http://www.yahoo.com''http://javascript.neyric.com/blog''http://javascript.neyric.com/wireit''http://neyric.github.com/inputex'
8    }, 
9    value: ['http://www.neyric.com''http://www.ajaxian.com''http://www.google.com''http://www.yahoo.com'],  
10    parentEl: 'container5'
11    useButtons: true  
12}); 
view plain | print | ?

Field names

The names are automatically set on sub-fields, so that standard forms can work. Click the button and check the URL

1 new inputEx.Form( { 
2fields: [ 
3
4    name: 'firstVar'
5    label: "First variable"
6    value: "my-custom-value" 
7}, 
8
9    type: 'list'
10    label: "My Array"
11    maxItems: 4, 
12    minItems: 1, 
13    elementType: {type: 'string'}, 
14    value: ['this''is''a''test'], 
15    name: 'myarray'
16    useButtons: true , 
17    sortable: true 
18}], 
19   buttons: [{type: 'submit', value: 'Test to send the GET request'}], 
20method: 'GET'
21parentEl: 'container6' 
22); 
view plain | print | ?