View Full Version : Is there a sane way to validate 2 fields against each other

24 Apr 2015, 9:23 AM
In Django we have field validation and form validation and the errors are stored on the form. In extjs we have field validation and the error seems to be stored on the field. This makes it virtually impossible to validate 2 fields against each other without some crazy hacks.

I have a form with several fields, you can chose 'none' for field A and 'none' for field B. If both of them are 'none' then we have 2 fields that are in error. If either of them is not 'none' then they are both ok.

I'm having to call A.validate() inside the B.isValid() and vice versa, then I have to introduce a closure and a boolean to keep me from running out of stack because they are each calling each other.

There should be some way (other than isValid()) to set a field to invalid, so a form validation could rule the form invalid and mark the fields as needing to be fixed. I can find no examples of this on the web.

24 Apr 2015, 1:37 PM

Take a look at VTypes (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.VTypes). You can create a custom one for your 2 fields that depend on each other and validate that way.


Hope this helps,