inputEx - CheckBox Usage

Basic CheckBox creation

Use the following code to create a basic inputEx CheckBox.

1new inputEx.CheckBox({parentEl: 'container1'}); 
view plain | print | ?

With a label

Add the label

1new inputEx.CheckBox({label: 'Do you like inputEx ?', rightLabel: 'Check me !', parentEl: 'container2', value: false}); 
view plain | print | ?

Default returned values

In its simplest form, the CheckBox returns true if checked, false otherwise.

1var exampleDiv = YAHOO.util.Dom.get('container3'); 
2var field1 = new inputEx.CheckBox({rightLabel: 'I return true/false', parentEl: exampleDiv}); 
3var button = inputEx.cn('button'nullnull'getValue()'); 
4exampleDiv.appendChild(button);  
5YAHOO.util.Event.addListener(button, 'click'function() { alert(field1.getValue()); }); 
view plain | print | ?

Changing the returned values

You can return different values if needed.

1var exampleDiv = YAHOO.util.Dom.get('container4'); 
2var field2 = new inputEx.CheckBox({sentValues: ['Yes''No'], rightLabel: 'Do you agree ?', parentEl: exampleDiv, value: 'Yes'}); 
3var button = inputEx.cn('button'nullnull'getValue()'); 
4var button2 = inputEx.cn('button'nullnull'setValue("No")'); 
5var button3 = inputEx.cn('button'nullnull'setValue("Yes")'); 
6exampleDiv.appendChild(button);  
7exampleDiv.appendChild(button2);  
8exampleDiv.appendChild(button3);  
9YAHOO.util.Event.addListener(button, 'click'function() { alert(field2.getValue()); }); 
10YAHOO.util.Event.addListener(button2, 'click'function() { field2.setValue('No'); }); 
11YAHOO.util.Event.addListener(button3, 'click'function() { field2.setValue('Yes'); }); 
view plain | print | ?

Updated event

How to listen to the updated event :

Log :
1var el = YAHOO.util.Dom.get('container5'); 
2var field = new inputEx.CheckBox({parentEl: el }); 
3var logDiv = inputEx.cn('div'nullnull"Log :"); 
4el.appendChild(logDiv); 
5field.updatedEvt.subscribe(function() { 
6    logDiv.innerHTML += "Updated at "+(new Date())+" with value : "+field.getValue(); 
7    logDiv.appendChild(inputEx.cn('br')); 
8}); 
view plain | print | ?

Disabling checkboxes

How to enable/disable a checkbox :

1var dc = new inputEx.CheckBox({label: 'Disable', parentEl: 'container6'}); 
2dc.disable(); 
view plain | print | ?