Results 1 to 3 of 3

Thread: Custom text field validator is not executed if the field is blank

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Ext JS Premium Member
    Join Date
    Dec 2009
    Posts
    65

    Default Custom text field validator is not executed if the field is blank

    REQUIRED INFORMATION

    Ext version tested:
    • Ext 4.1-beta-2
    • Ext 3.4

    Browser versions tested against:

    • IE9

    Description:
    • If a form field has a custom validator (vtype), it will not be executed if the field is blank
    • I had a validator assigned to a combobox field that was making sure the field is not blank, but only if there is something to select from the dropdown. If the dropdown is empty, the field was allowed to be left blank.
    • I can see other scenarios where the field may not be allowed to be left blank based on the values of other fields, or some other criteria.

    Steps to reproduce the problem:
    • Create a custom vtype, add it to Ext.form.field.VTypes
    • Create a form with a field that has the custom vtype assigned
    • Validate the form when the field is blank

    The result that was expected:
    • the custom validator is executed

    The result that occurs instead:
    • the custom validator is not executed

    HELPFUL INFORMATION

    Debugging already done:
    • This worked in ExtJS 3.3 and was broken in 3.4 when the "return errors" line was added in the getErrors function in TextField:

    Code:
        getErrors: function(value) {
            ...
            if (value.length < 1 || value === emptyText) {
                if (!allowBlank) {
                    errors.push(me.blankText);
                }
                //if value is blank, there cannot be any additional errors
                return errors;
            }
            ...
            if (vtype) {
                if(!vtypes[vtype](value, me)){
                    errors.push(me.vtypeText || vtypes[vtype +'Text']);
                }
            }
            ...
        }
    Possible fix:
    • remove the "return errors;" statement, or
    • move the "if (vtype)" block up.

    I think the first option is safer.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,451

    Default

    This is because there isn't anything to validate against. allowBlank is the validation for empty values.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

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

  3. #3
    Ext JS Premium Member
    Join Date
    Dec 2009
    Posts
    65

    Default

    Sorry, I did not get that. You have to let the custom validators execute regarless of what the field value is. Nobody knows what the logic in custom validators is.

    I have a custom vtype called 'select':

    Code:
    Ext.apply(Ext.form.field.VTypes, {
        select: function (value, combo) {
            if (combo instanceof Ext.form.field.ComboBox) {
                return !Ext.isEmpty(value) || combo.getStore().find(combo.displayField, /\S/) == -1;
            }
            else {
                return false;
            }
        },
        selectText: 'This field is required'
    });
    It worked great in 3.3. It marked the ComboBox field with vtype: 'select' as 'failed validation' if the associated store was not empty. I cannot use allowBlank for this.

    Now it's broken with no flexible workaround other than override getErrors and remove the return statement.

Tags for this Thread

Posting Permissions

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