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 more easily be done with the “validator” config setting.
The validator triggers a function that comes with 2 parameters: the number field itself (object) and the raw value. It is a pitty that Sencha didn’t think of adding the parent/form as well. I have put a working sample in JSFiddle. To get the first field in a variable, I have 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) has to be equal or smaller than the first field (Field One).