PDA

View Full Version : Raise Event For Two or More Checkboxes



elshae
22 Feb 2011, 7:57 AM
I have an interesting situation. I have a form with some checkboxes and radio buttons. I need an event that will fire when 2 or more of these checkboxes are checked and will disable the corresponding radio buttons.

24794

So in this case since checkbox 10 and 11 are clicked, I need radio button 10 and 11 enabled and the rest disabled/greyed out. Each of the checkboxes and radio buttons are created dynamically. I have tried using the checked event, but to be honest I do not really understand what I'm doing. I'd really appreciate if anyone could give me a little direction...

I'm not putting much code here because there's a lot going on here. This form is actually created as the result of a button being clicked after two or more rows are checked on a grid...


namesStore.load({
callback:function (records, options, success) {
//console.log(success); For FireBug
if (success) {
var ct = records.length, it = 0;

while (it < ct) {

Ext.getCmp('namesFieldset').add(new Ext.form.Checkbox({
boxLabel: " < " + checkedRecords[it].get('location') + " | " + checkedRecords[it].get('name') + " | " + checkedRecords[it].get('transliteration') + " | " +
checkedRecords[it].get('source') + " | " + checkedRecords[it].get('located_true') +
" > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; < " +
records[it].get('name') + " | " + records[it].get('transliteration') + " | " +
records[it].get('source') + " | " + records[it].get('located_true') + " > ",
id: checkedRecords[it].get('location'), listeners: {check: function getLocationsForDisplay(checkboxes, placeNamesApplyForm, plgrps) {
if(checkboxes.length == 2){
placeNamesApplyForm.cascade(function(cmp) {
for(var d = 0; d < plgrps.length; d++){
if (cmp.isXType('radio') && cmp.getId() != plgrps[d]) {
cmp.disable();
}else if(cmp.isXType('radio') && cmp.getId() == plgrps[d]){
cmp.enable();
}
}
});
}
}}
}));

The getLocationsForDisplay() was my attempt to this. I was trying to see if I could pass some variables from outside the load(), which are probably out of scope and not what a checked handler expects. Hope someone can give me tips :)

Thank you,

elshae

elshae
22 Feb 2011, 8:36 AM
Ok so I managed to get something...now when I click a checkbox the event fires, but it disables ALL my radio buttons!!! And it only seems to fire once?


namesStore.load({
callback:function (records, options, success) {
//console.log(success); For FireBug
if (success) {
var ct = records.length, it = 0;

while (it < ct) {

Ext.getCmp('namesFieldset').add(new Ext.form.Checkbox({
boxLabel: " < " + checkedRecords[it].get('location') + " | " + checkedRecords[it].get('name') + " | " + checkedRecords[it].get('transliteration') + " | " +
checkedRecords[it].get('source') + " | " + checkedRecords[it].get('located_true') +
" > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; < " +
records[it].get('name') + " | " + records[it].get('transliteration') + " | " +
records[it].get('source') + " | " + records[it].get('located_true') + " > ",
id: checkedRecords[it].get('location'), listeners: {check: function (checkbox, value) {
if(value == true){
placeNamesApplyForm.cascade(function(cmp) {
for(var d = 0; d < checkedRecords.length; d++){
if (cmp.isXType('checkbox') && cmp.getValue() && cmp.getId() == checkedRecords[d].get('location')) {
Ext.getCmp(checkedRecords[d].get('place_group')).enable();
}//end if
else {
Ext.getCmp(checkedRecords[d].get('place_group')).disable();
}
}//end for
});
}//end if
}}
}));

Ext.getCmp('displayFieldset').add(//new Ext.form.Radio({
{
boxLabel: "Location: " + checkedRecords[it].get('location') + " &nbsp;Source = " +
checkedRecords[it].get('source') + " &nbsp;Located True = " + checkedRecords[it].get('located_true'),
id: checkedRecords[it].get('place_group'), name: 'display',
inputValue: checkedRecords[it].get('location') }

//})
);

if(typeof records[it].get('distance') != 'undefined'){
var distances = records[it].get('distance').split("|");
for(var d = 0; d < distances.length; d++){
if(distances[d] != ""){
Ext.getCmp('distanceFieldset').add(new Ext.form.TextField({
value: distances[d], readOnly: true, width: 600}));
}
}
}
it++;
}
}
Ext.getCmp(checkedRecords[0].get('place_group')).setValue(true);
placeNamesApplyWindow.show();
}
});

elshae