PDA

View Full Version : [SOLVED] Form has fieldset with checkboxToggle. How do I verify if it is (un)checked?



kevin-berry
28 Jun 2010, 9:22 AM
When a form is submitted after the user clicks the submit button, I want to determine if my checkboxToggled fieldset (id: parent_sub_id) is checked or not. I have tried using getDom, but to no avail. Here is the code for the form itself:

Ext.BLANK_IMAGE_URL = 'ext-3.2.1/resources/images/default/s.gif';

var backendURL='create_form_code.php';

Ext.namespace('kberry_create_form');

kberry_create_form.app = function()
{
Ext.onReady(function(){

//quicktips shows validation errors and tips, I assume on the 'side'
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

var Parent_Sub_ID =
{
xtype:'fieldset',
checkboxToggle:true,
title: 'Parent Submission ID',
name: 'parent_sub_id',
id: 'parent_sub_id',
autoHeight:true,
collapsed: true,
items : [{
xtype:'textarea',
fieldLabel: 'Auxiliary Text',
name: 'pid_aux_text',
id: 'pid_aux_text',
height:75,
width:400,
autoScroll:true,
emptyText: 'If left blank, Auxiliary Text defaults to \"Please leave this field blank ' +
'if you do not wish to link this submission with a previously made submission.\"',
}, pid_rank, pid_searchable,
]
}


var default_buttons =
[{
text: 'Create Form',
handler: function()
{
var form_name = Ext.getCmp('form_name').getValue();
alert("You are attempting to create a form called " + form_name);
var col = Ext.getDom('parent_sub_id').collapsed;
alert("PID: " + col);
var post_params = "ajax_action=check_form_name&form_name=" + form_name;
create_http_request();
alert("Sending request...");
send_http_request(handler_check_form_name, "POST", target_url, post_params);
}

}];

///
///THE FORM
///

var fp = new Ext.form.FormPanel
({
frame:true,
applyTo: 'content',
name: 'create_form_form',
id: 'create_form_form',
items: [
{
layout:'column',
border:false
},
Parent_Sub_ID,
], //end items
buttons: default_buttons
}); //end actual form creation

}); //end onReady
}(); //End of namespace

When the user clicks the submit button, I try to do a check to see if the parent_sub_id checkToggle is indeed on or off:


var col = Ext.getDom('parent_sub_id').collapsed;
alert("PID: " + col);

col, however, always returns true, since this is initially what the value of the config option 'collapsed' is set as. I need to have the value of that box after the user has played with it. Therefore, it could be false - that is, the fieldset may be expanded by the user. I need to know this.

Can anyone provide a suggestion as to why it's not behaving that way?



Thanks for your suggestions.

Kevin

fay
28 Jun 2010, 10:06 AM
Try specifying a checkboxName (http://www.sencha.com/deploy/dev/docs/?class=Ext.form.FieldSet&member=checkboxName) and then you should be able to use Ext.get (getCmp?) to test it's status. Alternatively, look at the full documentation for checkboxToggle where you can specify a DomHelper spec, including an 'id', so you can use Ext.get().

EDIT:

I just tried it this way and it works:



// ...

checkboxToggle: {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id + '-checkbox', id: 'test-checkbox'},

// to test:

var isFieldSetChecked = Ext.get('test-checkbox').dom.checked;

kevin-berry
28 Jun 2010, 11:12 AM
*big smile* Perfect! Thanks so much. I had done some digging and was about to reply, unsure of how to properly use the DomHelper, but then saw your edit. Tried it and voila! Huuuge help, thanks!