Colin
Colin

Reputation: 1855

ExtJS: default validation

95% of my fields for a form I have use a custom validator -> hence I include it as apart of my defaults config of the container.

However, for the remaining 5% of fields, I want to use the built-in validation. Is there a way to manually specify using the default validator for a given field type?

Currently I try,

{
    name: 'normalNumberField',
    xtype: 'numberfield',
    validator: Ext.form.field.Number.validate,
    ...
}

but I'm getting an error that Ext.form is undefined (why? I clearly have a reference to Ext ... )

Upvotes: 1

Views: 2571

Answers (1)

Towler
Towler

Reputation: 1562

The validator is not specified by default. Number field validation occurs in multiple steps (this is taken from the ExtJS docs):

  1. Field specific validator

    A validator offers a way to customize and reuse a validation specification. If a field is configured with a validator function, it will be passed the current field value. The validator function is expected to return either:

    • Boolean true if the value is valid (validation continues).
    • a String to represent the invalid message if invalid (validation halts).
  2. Basic Validation

    If the validator has not halted validation, basic validation proceeds as follows:

    • allowBlank : (Invalid message = blankText)

      Depending on the configuration of allowBlank, a blank field will cause validation to halt at this step and return Boolean true or false accordingly.

    • minLength : (Invalid message = minLengthText)

      If the passed value does not satisfy the minLength specified, validation halts.

    • maxLength : (Invalid message = maxLengthText)

      If the passed value does not satisfy the maxLength specified, validation halts.

  3. Preconfigured Validation Types (VTypes)

    If none of the prior validation steps halts validation, a field configured with a vtype will utilize the corresponding Ext.form.field.VTypes validation function. If invalid, either the field's vtypeText or the VTypes vtype Text property will be used for the invalid message. Keystrokes on the field will be filtered according to the VTypes vtype Mask property.

  4. Field specific regex test If none of the prior validation steps halts validation, a field's configured regex test will be processed. The invalid message for this test is configured with regexText

  5. Number field specific validation

    The additional validations run test that the value is a number, and that it is within the configured min and max values.

So, long story short, to override your validator that you specified in defaults, you can simply use a validator which always returns true.

{
    name: 'normalNumberField',
    xtype: 'numberfield',
    validator: function(){ return true; },
    ...
}

Upvotes: 2

Related Questions