Adobe-Consulting-Services / acs-aem-commons

http://adobe-consulting-services.github.io/acs-aem-commons/
Apache License 2.0
453 stars 600 forks source link

Multifield is validating even if disabled #835

Closed GonzaloCalandria closed 7 years ago

GonzaloCalandria commented 8 years ago

I'm using a multifield with a multifieldpanel (with the property minItems=1) and this is being enabled/disabled using a checkbox. If the checkbox is disabled, the multifield is being validated and this is making a validation error when the multifield is empty (and disabled).

I've able to fix this in the bellow code but i would like to know if this is really an issue or i'm having a bad implementation:

validate: function() {
            //BEGIN The multifield is disabled FIX
            if(this.hasClass("x-masked")) {
                return true;
            }
           //END The multifield is disabled FIX
            if (this.minItems && (this.getActualItemCount() < this.minItems)) {
                if (!this.allowZeroItems) {
                    this.markInvalid("This field must have at least " + this.minItems + " items.");                    
                    return false;
                } else if (this.getActualItemCount() > 0 ) {
                    this.markInvalid("This field must have 0 items or at least " + this.minItems + " items.");
                    return false;
                }
            }
            if (this.maxItems && (this.getActualItemCount() > this.maxItems)) {
                this.markInvalid(CQ.I18n.get('You are only allowed to add {0} items to this field', [this.maxItems]));
                return false;
            }

            return originalValidateFunction.apply(this);
        },
davidjgonzalez commented 7 years ago

@GonzaloCalandria in the interim, could you do something like ...

(function() {
    var acsCommonsValidateFunction = CQ.form.MultiField.prototype.validate;
    CQ.Ext.override(CQ.form.MultiField, {

        validate: function() {
            //BEGIN The multifield is disabled FIX
            if(this.hasClass("x-masked")) {
                return true;
            }
            //END The multifield is disabled FIX

            return acsCommonsValidateFunction.apply(this);
        }
    });
}());

and make that JS part of a clientlibs dependency that is dependent on acs-commons.cq.widgets

Been awhile since ive done anything w ExtJS (TG) so not sure how well that'll work.

davidjgonzalez commented 7 years ago

ClassicUI