PDA

View Full Version : Form Validation (disabled fields)



harley.333
3 Oct 2011, 8:33 AM
I have a recurrence scheduling app which uses a Card layout to display options for "Daily, Weekly, etc." The Weekly card displays a checkboxgroup containing a checkbox for each day of the week. I've placed allowBlank:false on the checkboxgroup because I don't the user to specify a weekly schedule with no days selected.

However, if the user selects a daily schedule, I don't want the weekly validation rule to get in the way.

How can I get around this?

When the card-layout is changed, I am currently disabling all non-selected cards. I thought validation for disabled fields did not occur.

Thanks,
Harley

harley.333
3 Oct 2011, 8:56 AM
It appears that setting 'disabled' on a field does not fire the validitychange event. Does this sound like a bug?

harley.333
3 Oct 2011, 9:46 AM
There ended up being two issues.
1. When a field is disabled/enabled, it is not re-validated. I think it should be since the disabled status makes a difference to validation.
2. The CheckboxGroup pays no attention to its own disabled status.

The following modifications got what I wanted.


Ext.form.field.Field.prototype.enable = function () {
this.callParent(arguments);
this.validate();
};
Ext.form.field.Field.prototype.disable = function () {
this.callParent(arguments);
this.validate();
};

Ext.form.CheckboxGroup.prototype.validate = function () {
var me = this,
errors = me.getErrors(),
isValid = me.disabled || Ext.isEmpty(errors),
wasValid = !me.hasActiveError();

if (isValid) {
me.unsetActiveError();
} else {
me.setActiveError(errors);
}
if (isValid !== wasValid) {
me.fireEvent('validitychange', me, isValid);
me.doComponentLayout();
}

return isValid;
};

If I were working on the ExtJS code-base, I would still have the question of how a CheckboxGroup validates if only some of the checkboxes (within the group) are disabled. But that's outside the scope of my current issue.

Thanks!