-
5 Oct 2008 11:41 PM #1
Form Validation when one field is dependent on another form field
Form Validation when one field is dependent on another form field
HI All,
I have one form in which I have one combo box (Combo) and another text box(Text) which is enabled on certain values selected of combo box.I need to submit the form and validate manadatory field on Text if it is enabled. I have defined allowBlank : false for both Combo and the Text. and also I have added addForm.getForm().isValid() before submitting the form.
My problem is that when Text is enabled the validation works perfectly and red line is shown if Text is empty but when Text is disabled then also red line is shown though value of addForm.getForm().isValid() is true.
Can someone help me out how to get rid of that redline (sign of mandatory field).
Thanks.
-
6 Oct 2008 12:26 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
formPanel.getForm().isValid() should clear the invalid mark on all disabled fields.
However, field.isValid() doesn't do this (use field.validate() instead).
-
6 Oct 2008 1:30 AM #3
Hi Thanks a lot for quick reply!
But formPanel.getForm().isValid() is not clearing invalid mark. I have tried to reset the form and disable and applied the fieldLabel for the Text.
addForm.getForm().isValid();
addForm.getForm().reset();
otherText.setDisabled(true);
Ext.getCmp('otherText').setFieldLabel('Set new label');
Though it is giving the desired result but not sure whether this is the correct approach!
-
6 Oct 2008 1:41 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
field.reset() and form.getForm().reset() clear the invalid mark, but I still say that form.getForm().isValid() should also do this!
Could you post a small example that demonstrates the problem?
-
6 Oct 2008 2:11 AM #5
Hi this is the code snippet where I was facing the problem :
addForm = new Ext.FormPanel({
frame: true,
monitorValid:true,
bodyStyle: 'padding:5px 5px 0',
items: [{
layout: 'column',
items: [{
layout: 'form',
columnWidth: 0.5,
items:[otherCombo,otherText]
}]
}],
buttons: [{
text: 'Add',
id:'addBtn',
formBind:true,
handler: function(){
if(!addForm.getForm().isValid()){
return false;
}
}]
});
var otherText=new Ext.form.TextField({
fieldLabel: 'Other',
autoCreate : {tag: 'input', type: 'text', maxlength: '50', autocomplete: 'off'},
id: 'otherText',
allowBlank:false,
anchor:'80%'
});
I hope Combo's code is not required here for the example.
-
6 Oct 2008 2:37 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
1. I removed monitorValid:true.
2. I changed the handler to:
3. No invalid mark appears.Code:otherField.setDisabled(true); if(!addForm.getForm().isValid()){ ... }
-
6 Oct 2008 3:12 AM #7
-
6 Oct 2008 3:16 AM #8Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
No, that's not what I meant. monitorValid:true will regularly call isValid on all fields and enable/disable all bound buttons. It's not required, but a nice optional feature.
I needed to remove monitorValid, otherwise I could not click the button when the field was invalid (just for the example).
-
6 Oct 2008 3:49 AM #9
Okay...I think I got you point. Thanks a lot for your prompt reponses and support



Reply With Quote