Results 1 to 10 of 10

Thread: [4.1.2] TextField ignores VType validation if no value

    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
    1,017
    Vote Rating
    125
      0  

    Default [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>

    Object.NET
    Frameworks and Tools for .NET Developers
    --------------------------------------------------
    Ext.NET - Ext JS for ASP.NET - Examples | Twitter
    Bridge.NET - Write C#. Run JavaScript! - Live | Twitter
    --------------------------------------------------

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,060
    Vote Rating
    1389
      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 @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,001
    Vote Rating
    936
      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.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #4
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    1,017
    Vote Rating
    125
      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.
    Object.NET
    Frameworks and Tools for .NET Developers
    --------------------------------------------------
    Ext.NET - Ext JS for ASP.NET - Examples | Twitter
    Bridge.NET - Write C#. Run JavaScript! - Live | Twitter
    --------------------------------------------------

  5. #5
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,862
    Vote Rating
    87
      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());
                    }
                });
            });
    Longtime Sencha engineer. Now surplus to requirements apparently...

  6. #6
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    1,017
    Vote Rating
    125
      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.
    Object.NET
    Frameworks and Tools for .NET Developers
    --------------------------------------------------
    Ext.NET - Ext JS for ASP.NET - Examples | Twitter
    Bridge.NET - Write C#. Run JavaScript! - Live | Twitter
    --------------------------------------------------

  7. #7
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,862
    Vote Rating
    87
      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.
    Longtime Sencha engineer. Now surplus to requirements apparently...

  8. #8
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,862
    Vote Rating
    87
      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
    1,017
    Vote Rating
    125
      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.)
    Object.NET
    Frameworks and Tools for .NET Developers
    --------------------------------------------------
    Ext.NET - Ext JS for ASP.NET - Examples | Twitter
    Bridge.NET - Write C#. Run JavaScript! - Live | Twitter
    --------------------------------------------------

  10. #10
    Sencha User Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    1,017
    Vote Rating
    125
      0  

    Default

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

    Thank you for adding!
    Object.NET
    Frameworks and Tools for .NET Developers
    --------------------------------------------------
    Ext.NET - Ext JS for ASP.NET - Examples | Twitter
    Bridge.NET - Write C#. Run JavaScript! - Live | Twitter
    --------------------------------------------------

Posting Permissions

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