Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-7625 in 4.2.0.663.
  1. #1
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    974
    Vote Rating
    110
    Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all

      0  

    Default [4.1.2] TextField ignores VType validation if no value

    [4.1.2] TextField ignores VType validation if no value


    REQUIRED INFORMATION

    Ext version tested:
    • Ext 4.1.2
    Browser versions tested against:
    • IE9
    • Chrome
    DOCTYPE tested against:
    • <!DOCTYPE html>
    Description:
    • TextField ignores VType validation if no value.
    • Yes, I can use allowBlank, but it is not an option, because I need to provide some custom "allowBlank" validation.
    Steps to reproduce the problem:
    • Click the Button
    The result that was expected:
    • The field is invalid according VType validation
    The result that occurs instead:
    • The field is valid
    Test Case:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <title>TextField VType is ignored if no value</title>
    
        <link type="text/css" rel="stylesheet" href="../resources/css/ext-all.css" />
        
        <script type="text/javascript" src="../ext-all-debug.js"></script>
    
        <script type="text/javascript">
            Ext.apply(Ext.form.field.VTypes, {
                myvtype: function () {
                    return false;
                }
            });
    
            Ext.onReady(function () {
                Ext.create("Ext.form.field.Text", {
                    id: "field1",
                    renderTo: Ext.getBody(),
                    vtype: "myvtype"
                });
    
                Ext.create("Ext.button.Button", {
                    renderTo: Ext.getBody(),
                    text: "isValid",
                    handler: function () {
                        alert(Ext.getCmp("field1").isValid());
                    }
                });
            });
        </script>
    </head>
    <body>
    
    </body>
    </html>

    Ext.NET - ASP.NET for Ext JS
    MVC and WebForms
    Examples | Twitter

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,032
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This is a fundamental change. On one had I would agree but on the other hand there is no value to validate against and this is what allowBlank is for.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,909
    Vote Rating
    626
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    This is by design. The validator function trumps everything. If the value is blank, and we've got allowBlank, then it just jumps out.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  4. #4
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    974
    Vote Rating
    110
    Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all

      0  

    Default


    Hi Mitchell and Evan,

    Thank you for the answers.

    Yes, I understand that it is by design and it is a big deal to change.

    I am just drawing your attention to this problem. Maybe, the chosen design was not the best one. Personally, I would not ignore VType (and validator as well) if no value. It would allow to clearly accomplish, for example, a common task to validate a field for password confirmation.

    Now our "password" VType looks:
    Code:
    password : function (val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return pwd ? (val === pwd.getValue()) : false;
        }
    
        return true;
    },
    
    passwordText : "Passwords do not match"
    Everything is good except a case when a field is empty.

    I think there can be many other scenarios where we need "allowBlank" validation according some external condition (like in my case - 'if a primary password field is not empty').

    Yes, there is a simple workaround - listen the "change" event of the primary password field to set allowBlank to true for the secondary password field. But it is a trick.
    Ext.NET - ASP.NET for Ext JS
    MVC and WebForms
    Examples | Twitter

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

      0  

    Default


    This makes it invalid

    Code:
            Ext.apply(Ext.form.field.VTypes, {
                myvtype: function () {
                    return false;
                }
            });
    
            Ext.onReady(function () {
                Ext.create("Ext.form.field.Text", {
                    id: "field1",
                    renderTo: Ext.getBody(),
                    validator: function() {
                        return false;
                    }
                });
    
                Ext.create("Ext.button.Button", {
                    renderTo: Ext.getBody(),
                    text: "isValid",
                    handler: function () {
                        alert(Ext.getCmp("field1").isValid());
                    }
                });
            });

  6. #6
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    974
    Vote Rating
    110
    Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all

      0  

    Default


    Thanks, @Animal! It is very good.

    Could you kindly share your opinion for "Should VType be ignored if no value?". It is rather a design issue.
    Ext.NET - ASP.NET for Ext JS
    MVC and WebForms
    Examples | Twitter

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

      0  

    Default


    This is a discussion which has been had here many times.

    The allowBlank flag functions as a "blankAlwaysValid" flag.

    See this from 2008: http://www.sencha.com/forum/showthre...llowBlank-set&

    It's just established in the API.

    We could probably have another flag which decides whether it means blank should bypass all other validation which would be true by default to maintain behaviour.

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

      2  

    Default


    Thanks for the report! I have opened a bug in our bug tracker.

    We need to make this flexible so that people can apply validation to blank values!

  9. #9
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    974
    Vote Rating
    110
    Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all

      0  

    Default


    That is great! Thank you, @Animal!

    It would be very nice if you could look at this issue.
    http://www.sencha.com/forum/showthread.php?242897

    It is a very severe issue for our toolkit based on ExtJS.

    (Apologize for a trick. Please ignore if you wish.)
    Ext.NET - ASP.NET for Ext JS
    MVC and WebForms
    Examples | Twitter

  10. #10
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    974
    Vote Rating
    110
    Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all Daniil is a name known to all

      0  

    Default


    For someone who is interested in: the validateBlank flag has been added. It is false by default.

    Thank you for adding!
    Ext.NET - ASP.NET for Ext JS
    MVC and WebForms
    Examples | Twitter