Results 1 to 4 of 4

Thread: [UNKNOWN][3.*,2.*]DateField.validateValue calls superclass's validateValue too soon

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,855
    Vote Rating
    88
      0  

    Default [UNKNOWN][3.*,2.*]DateField.validateValue calls superclass's validateValue too soon

    Check the examples/form/adv-vtypes example. With the latest markInvalid fix defining msgDisplay as ''!

    If you type in an invalid date, it performs TextField's validateValue first, before applying date validation.

    This causes an incorrect error message to be displayed.

    DateField.validateValue needs to be

    Code:
    Ext.override(Ext.form.DateField, {
        validateValue : function(value){
            value = this.formatDate(value);
            if(!Ext.form.DateField.superclass.validateValue.call(this, value)){
                return false;
            }
            if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
                 return true;
            }
            var svalue = value;
            value = this.parseDate(value);
            if(!value){
                this.markInvalid(String.format(this.invalidText, svalue, this.format));
                return false;
            }
            var time = value.getTime();
            if(this.minValue && time < this.minValue.getTime()){
                this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
                return false;
            }
            if(this.maxValue && time > this.maxValue.getTime()){
                this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
                return false;
            }
            if(this.disabledDays){
                var day = value.getDay();
                for(var i = 0; i < this.disabledDays.length; i++) {
                    if(day === this.disabledDays[i]){
                        this.markInvalid(this.disabledDaysText);
                        return false;
                    }
                }
            }
            var fvalue = this.formatDate(value);
            if(this.disabledDatesRE && this.disabledDatesRE.test(fvalue)){
                this.markInvalid(String.format(this.disabledDatesText, fvalue));
                return false;
            }
    
    //      Perform TextField processing only after specialized Date validation
            if(!Ext.form.DateField.superclass.validateValue.call(this, value)){
                return false;
            }
            return true;
        }
    });
    Longtime Sencha engineer. Now surplus to requirements apparently...

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    128
      0  

    Default

    That would kill the allowBlank check. I suggest:
    Code:
    Ext.override(Ext.form.DateField, {
        validateValue : function(value){
            value = this.formatDate(value);
            /*if(!Ext.form.DateField.superclass.validateValue.call(this, value)){
                return false;
            }
            if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
                 return true;
            }*/
            if(value){ // The textfield will check allowBlank
                var svalue = value;
                value = this.parseDate(value);
                if(!value){
                    this.markInvalid(String.format(this.invalidText, svalue, this.format));
                    return false;
                }
                var time = value.getTime();
                if(this.minValue && time < this.minValue.getTime()){
                    this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
                    return false;
                }
                if(this.maxValue && time > this.maxValue.getTime()){
                    this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
                    return false;
                }
                if(this.disabledDays){
                    var day = value.getDay();
                    for(var i = 0; i < this.disabledDays.length; i++) {
                        if(day === this.disabledDays[i]){
                            this.markInvalid(this.disabledDaysText);
                            return false;
                        }
                    }
                }
                var fvalue = this.formatDate(value);
                if(this.disabledDatesRE && this.disabledDatesRE.test(fvalue)){
                    this.markInvalid(String.format(this.disabledDatesText, fvalue));
                    return false;
                }
            }
            // Perform TextField processing only after specialized Date validation
            return Ext.form.DateField.superclass.validateValue.call(this, value);
        }
    });
    (You can also save some bytes on the last few lines)

  3. #3
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,855
    Vote Rating
    88
      0  

    Default

    Yes. Well spotted.
    Longtime Sencha engineer. Now surplus to requirements apparently...

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,855
    Vote Rating
    88
      0  

    Default

    This one is still open.

    examples/form/adv-vtypes.html

    Type an invalid date into one of the DateFields, and it displays the message

    {0} is not a valid date - it must be in the format {1}
    Longtime Sencha engineer. Now surplus to requirements apparently...

Posting Permissions

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