Results 1 to 3 of 3

Thread: Form Validation (disabled fields)

  1. #1
    Sencha User harley.333's Avatar
    Join Date
    Mar 2007
    Posts
    286
    Answers
    1
    Vote Rating
    5
      0  

    Default Answered: Form Validation (disabled fields)

    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 - Harley Jones
    harley.333@gmail.com - Find me on Google Talk.

  2. 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.

    Code:
    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!

  3. #2
    Sencha User harley.333's Avatar
    Join Date
    Mar 2007
    Posts
    286
    Answers
    1
    Vote Rating
    5
      0  

    Default

    It appears that setting 'disabled' on a field does not fire the validitychange event. Does this sound like a bug?
    harley.333 - Harley Jones
    harley.333@gmail.com - Find me on Google Talk.

  4. #3
    Sencha User harley.333's Avatar
    Join Date
    Mar 2007
    Posts
    286
    Answers
    1
    Vote Rating
    5
      0  

    Default

    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.

    Code:
    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!
    harley.333 - Harley Jones
    harley.333@gmail.com - Find me on Google Talk.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •