1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    1
    Vote Rating
    0
    Brronek is on a distinguished road

      0  

    Default Validation of multiple fields

    Validation of multiple fields


    Hello

    I have validation issue, here is the scenario:

    1. I have 2 NumberFields, "from" and "to" and I want to validate if these two are propper interval, but open intervals (from is empty or to is empty) are allowed.
    2. These 2 fields has setAllowBlank(true) to hadnle open intervals
    3. I created my own private validator, that checks if :
    - both empty -> return error msg
    - both not empty and from < to -> return error msg
    - only one empty -> return null, this is allowed for open intervals
    4. I enter no data and call isValid() on FormPanel, that contains these fields
    5. Validator is not called, becouse fields allows blank, so futher validation is ingored

    Is there any other validation method to check if 2 numeric (and date) fields are proper interval?

    Regards
    Adam

  2. #2
    Ext JS Premium Member
    Join Date
    Nov 2007
    Location
    Greetings from Sol : Earth : Europe : Germany : MV : Rostock : S├╝dstadt
    Posts
    38
    Vote Rating
    0
    t34 is on a distinguished road

      0  

    Default


    Hello Brronek,

    i have the same challenge.
    Could you please give me a hint, how your create your "own private validator"?

    Thanks
    t34

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    A custom validator can be created by making a class that implements com.extjs.gxt.ui.client.widget.form.Validator. This custom validator can be given to any Field instance using the setValidator method.

    When validateValue is called on NumberField, it starts in SpinnerField.validateValue. This calls super.validateValue at about line 464, which, if it returns true, will continue on and run your custom validator, about line 517. Blank values should not be enough to prevent your custom validator from working in a NumberField.

Thread Participants: 2