Ext JS, Validate 2 number fields in form with a validator
Validate 2 number fields as alternative to a vtype
This post shows you how you can validate 2 number fields (Ext.form.field.Number) in an Ext JS (4) form.
Usually this is done with a vtype (Ext.form.field.VTypes), but this can be done more easily with the validator config setting.
The validator triggers a function that comes with 2 parameters:
- the number field (object)
- the raw value.
It is a bit sad that Sencha didn't think of adding the parent/form as well. I have added a working sample in JSFiddle. To get the first field in a variable, I used:
var form = this.up('form');
var field1 = form.down('#Field1');
Simply using:
var field1 = this.up('#Field1');
doesn't give any results.
Two number fields in a form and the second field (Field Two) have to be equal or smaller than the first field (Field One).
Sencha Fiddle Sample