View Full Version : Validation of multiple fields

27 Aug 2011, 7:39 AM

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?


7 Sep 2011, 1:15 AM
Hello Brronek,

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


Colin Alworth
8 Sep 2011, 6:45 AM
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.