PDA

View Full Version : radiogroup. user can unselect ?



maneljn
18 Jun 2014, 7:12 AM
If an user selects a radio field value in a form, is there any way that he can unselect it ? I mean , he choose one value, and then he wants to let the value empty...is it possible, without adding any other control (ex: button with action) ?

Manel

scottmartin
19 Jun 2014, 2:15 PM
You would have to override the default to allow you to toggle the image.

The other option is a single select checkbox group.

maneljn
19 Jun 2014, 11:15 PM
Scottmartin, do you have a piece of code of this ? "single select checkbox group"

Thanks
Manel

scottmartin
20 Jun 2014, 7:27 AM
Something like this:



Ext.onReady(function () {

Ext.create('Ext.form.Panel', {
title: 'Checkbox Group',
width: 300,
height: 125,
bodyPadding: 10,
renderTo: Ext.getBody(),
items:[
{
xtype: 'checkboxgroup',
fieldLabel: 'Two Columns',
columns: 2,
vertical: true,

listeners: {
change: function(checkbox, newValue, oldValue) {
if (Ext.isArray(oldValue.rb)) {
oldValue.rb = oldValue.rb[0];
}

if (newValue.rb && newValue.rb.length > 1) {
newValue.rb.splice(newValue.rb.indexOf(oldValue.rb),1);
checkbox.setValue({ rb: newValue.rb });
}
}
},

items: [
{ boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
{ boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
{ boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
{ boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
{ boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
{ boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
]
}

]
});

});