PDA

View Full Version : checkbox changed state



mgalesic
14 Jun 2011, 12:27 AM
I can get checkbox state with:


var c = Ext.getCmp("my_checkbox").checked;
but when i click the checkbox I don't get the new state.

Some checkboxes are going to be checked, some unchecked and user can change state. When he's done, i need to collect all the checkboxes with changed state by pressing the button.

I get this code on some other forum:


new Ext.form.Checkbox({
id: 'my_checkbox',
listeners: {
check: function() {
alert('I was checked!');
},
uncheck: function() {
alert('I was unchecked!');
}
}
});
does that mean that I need to follow every checkbox click, or is there way to get only the final states by pressing the button?

endre
14 Jun 2011, 1:59 AM
not sure if this is the "correct" way to do this, but you could have a variable for each check box and set the state when the user interacts:




var my_checkbox_state = false;

new Ext.form.Checkbox({
id: 'my_checkbox',
listeners: {
check: function() {
my_checkbox_state = true;
},
uncheck: function() {
my_checkbox_state = false;
}
}
});

mgalesic
14 Jun 2011, 2:16 AM
I' try that,

just one more thing,
in what do i change :


new Ext.form.Checkbox({
id: 'my_checkbox'


if i have this structure:



var filter = {

id: 'filter',

items: [{

xtype: 'fieldset',

items: [{
type: 'checkboxfield',
name: 'city[1]',
label: 'city',
id: 'city1',
checked: true,
},
{
xtype: 'checkboxfield',
name: 'city[2]',
label: 'City name 2',
id: 'city2'
}
] // END items

}] // END items

};
i'm still learning, please help

mgalesic
14 Jun 2011, 6:45 AM
I have add new checkboxes by:


filter.items[0].items[filter.items[0].items.length] = {
xtype: 'checkboxfield',
name: 'city['+city_id+']',
label: city[city_id] + ' <span class="num">' + city_num[city_id] + '</span>',
checked: (city_state[city_id] == '1' ? true : false),
cls: 'checkbox',
id: 'city_' + city_id,

}but I don't get anything by:



new Ext.form.Checkbox({
id: 'my_checkbox',
listeners: {
check: function() {
alert('I was checked!');
},
uncheck: function() {
alert('I was unchecked!');
}
}
});