PDA

View Full Version : How can you tell if a form has been validated yet?



DocAhrens
24 Apr 2012, 4:14 PM
I have a complex form with radio buttons followed by number fields and combo box fields that may or may not be required depending on which radio buttons have been selected. Because of the complexity of the form, the build in validation is not enough, so I put custom validate methods in the field declarations to dynamically set the field valid or not. But, there are some situations where radio buttons followed by number fields are not properly triggering the validitychange event, so even though the selections become valid, they do not appear properly validated until I submit the form. So, what I want to do is perform a form.isValid() when these complex radio/number fields are selected, but I only want to hit the isValid() method IF the form has already been validated - I don't want to force validation BEFORE the user has completed the form. How can I identify if a form has been validated yet?

DocAhrens
25 Apr 2012, 9:38 AM
In the initComponent of the window containing the form, I set a property

validated: false
in the form like so:


initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [{
xtype: 'form',
validated: false,

Then in the save method of the window, after firing:
form.isValid() I set:

form.validated = true
Then in whenever I want to know if it has already been validated, I view the form.validated property value. In the controller, I have a forceValidate method where I check the validated property first like so:


/**
* manually triggering validate, because the Checkbox Group is not doing it automatically
*/
forceValidate: function(el){
var frm = el.up('form').getForm();
if (frm.validated){
frm.isValid();
}
},

Seems like there should already be something like this, I just couldn't find it...