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 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:

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).


Johan van de Merwe
Dedicated to professional software development since 1985. Has worked since 1992 as IT manager in several international operating companies. Since 2007 CEO and Sencha Ext JS web application developer at Enovision GmbH.

Leave a Reply