1. #1
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default [FIXED][2.x] TextField bypasses other validation if allowBlank set

    [FIXED][2.x] TextField bypasses other validation if allowBlank set


    By default, the validateValue method in TextField checks for a zero-length (or == emptyText) value first, and if allowBlank is true, it returns with no more ado.

    This allows blank fields to bypass any other configured validation.

    You may say that the allowBlank setting means all bets are off, and the field is definitely valid. I don't believe this is the case. It means that blank is allowed, but configured validators; either the validator config, or vtype should also get their say.

    Also certain other postprocessing functionality in addition to pure validation often needs to be hung off a validator function.

    I suggest the following override which moves configured validation to the top of the method:

    Code:
    Ext.override(Ext.form.TextField, {
        validateValue : function(value){
            if(typeof this.validator == "function"){
                var msg = this.validator(value);
                if(msg !== true){
                    this.markInvalid(msg);
                    return false;
                }
            }
            if(this.vtype){
                var vt = Ext.form.VTypes;
                if(!vt[this.vtype](value, this)){
                    this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
                    return false;
                }
            }
            if(this.regex && !this.regex.test(value)){
                this.markInvalid(this.regexText);
                return false;
            }
            if(value.length < 1 || value === this.emptyText){ // if it's blank
                 if(this.allowBlank){
                     this.clearInvalid();
                     return true;
                 }else{
                     this.markInvalid(this.blankText);
                     return false;
                 }
            }
            if(value.length < this.minLength){
                this.markInvalid(String.format(this.minLengthText, this.minLength));
                return false;
            }
            if(value.length > this.maxLength){
                this.markInvalid(String.format(this.maxLengthText, this.maxLength));
                return false;
            }
            return true;
        }
    });

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Can this be changed?

    I know it's not a show stopping "bug".

    But as it stands, if blank is allowed, then all other validation is bypassed.

    A developer reasonably expects the validator, and any vtypes to be applied even is the field is blank.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    2
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    What's the use case for validating a blank value?

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Perhaps some rules, depending upon how the validation works would occasionally disallow blank even though it is allowed.

    More importantly, a [B]validator[B] may then be used for simply processing the field's value during typing if the BasicForm's monitorValid is true.

    But either way, that test at the top is too overriding. If null is allowed and it's null, then that overrides everything else - it's definitely valid. I's say it's just not invalid, conditional on other validation also passing.

    There's a 3 way choice here which is not covered.
    1. A validation can pass, and return immediately, ignoring other types of validation following on which might invalidate the value. This is what happens now.
    2. A validation can pass, and drop through to the next validation type to continue validation.
    3. A validation can fail. In which case, return early because it is invalid.

    Option 2 is not covered.

  5. #5
    Ext User
    Join Date
    Jul 2007
    Posts
    4
    Vote Rating
    0
    urskipfer is on a distinguished road

      0  

    Default


    I vote for Animals solution. For example I have a form in which a field can be blank or not debending on other fields. My validator checks the dependencies. But without Animals overwrite the function never reaches my validator.

  6. #6
    Sencha User
    Join Date
    Jun 2007
    Posts
    33
    Vote Rating
    0
    gtaylor is on a distinguished road

      0  

    Default Agree with Animal.

    Agree with Animal.


    I have a similar scenario to the previous reply. I'd like to see a 3rd option as Animal outlined.

  7. #7
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    +1, why would it be anything but what Animal is indicating?

  8. #8
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    +1, but it breaks backward compatibility.

  9. #9
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    It really is a bother.

    Blank may be valid, but it still needs to go through the validate routine so that the processing required can be performed. I need to see the value that the user input even if they input nothing!

    If I say allowBlank:false, then it just invalidates it immediately.

    There is no way of validating a blank value!

    The setting is not blankAlwaysValid, it is allowBlank!

  10. #10
    Ext User
    Join Date
    May 2007
    Posts
    1
    Vote Rating
    0
    pentium100 is on a distinguished road

      0  

    Default


    +1, i face the same problem too.