PDA

View Full Version : Added Ext.form.FieldSet isChecked() functionality



foxwhisper
3 Dec 2008, 10:51 AM
Hey guys,

Long time reader, first time poster. Found several posts on here that mentioned the fact that FieldSet didn't have an isChecked() function. The only fix at the time, was to disable the fieldset, which causes a few cross browser issues in Internet Explorer, and also meant tons of ugly code.

So, for anyone who wants to check if a FieldSet's checkbox is checked, use the following code:


// Add this to your includes
Ext.override( Ext.form.FieldSet, {
isChecked: function() {
return this.getEl().child('legend').child('input').dom.checked;
}
});

// Example Usage
alert(Ext.getCmp('myfieldsetcomponant').isChecked())



As far as I'm aware, the tree always follows that pattern to the FieldSet checkbox, and should work flawlessly, but if anyone knows otherwise, then feel free to modify and share!

<3

gthe
3 Dec 2008, 12:17 PM
I use this to read/write:


{
xtype:'fieldset',
checkboxToggle: {
type: 'checkbox',
tag: 'input',
name: 'is_mark',
id: 'id_is_mark'
},
title: 'Mark Trap',
items :[........]
}
and then:


Ext.get('id_is_mark').dom.checked = true

foxwhisper
3 Dec 2008, 12:24 PM
Ah yes,

See, the only problem doing it that way, is that you're unnecessarily creating references to objects which can be called much easily. With the function I posted, you can simply call the getCmp().isChecked() function, rather than having to go through and manually assign a unique ID to *every* fieldset checkbox :)

gthe
3 Dec 2008, 12:33 PM
And how You set value ?

foxwhisper
3 Dec 2008, 12:35 PM
You would use the already existing toggle() function, or collapse()/expand(), that way the event listeners will still do their jobs. If you go writing to the checkbox DOM object directly, you risk screwing up integrity within the ExtJS events (i think?)

gthe
3 Dec 2008, 12:46 PM
Do You try this methods ?

toggle is not a functioncollapse()/expand() !== check/uncheck

foxwhisper
3 Dec 2008, 12:50 PM
Sorry, use toggleCollapse() in the JavaScript on the fieldset component.

And actually, expand/collapse DOES == check/uncheck. If you execute a expand()/collapse() on a FieldSet, you will see the checkbox unchecks/checks itself. Please ensure you check your advice before posting, or the beginner users will get confused.

gthe
3 Dec 2008, 1:34 PM
I found my error. I add override from this post - http://extjs.com/forum/showthread.php?p=89918#post89918 and it cause don't check/uncheck when FieldSet collapse/Expand. Will try use others solutions.

Thank You!

evant
3 Dec 2008, 1:34 PM
You can just checked the collapsed property of the fieldset.

foxwhisper
3 Dec 2008, 2:20 PM
You can just checked the collapsed property of the fieldset.

The docs said that 'collapsed' was not a public property, and I believe that, when I tried to reference the property, it gave me an error in IE7. Should I raise this as a bug/feature request?

foxwhisper
3 Dec 2008, 4:26 PM
You can just checked the collapsed property of the fieldset.

Also, if I'm not mistaken, the 'collapsed' property will only show you the initial state as set within the configuration object. The actual current property is never updated when the fieldset is toggled, either in the events, or by user interaction. Thus, even if collapsed was a public property, it wouldn't contain the relevant information. Please correct me if I am wrong though!

evant
3 Dec 2008, 4:56 PM
That's not correct, check out the afterCollapse and afterExpand methods on the panel, they dynamically set the collapsed property on the class.

foxwhisper
3 Dec 2008, 4:59 PM
That's not correct, check out the afterCollapse and afterExpand methods on the panel, they dynamically set the collapsed property on the class.

Ah, I see. Sorry guys, my bad.