PDA

View Full Version : How to Change class prototype (ie, global defaults for form elements)?



xiinteractive
15 Aug 2011, 12:26 PM
Change class prototype properties/config (ie, global defaults for form elements)?

I would like to change the following config options globally for my app:
1. maxLength - defaults to Number.MAX_VALUE (infinity) ... I would like to set it to say maybe 100.
2. validationEvent: defaults to 'keyup'.... I would like to set it to 'blur'
3. validationDelay: defaults to 250. I might want to set this to something like 1500 if I dont change the validationEvent.

Limitations:
1. I do not want to change the EXTJS library of code... I would rather do this with Ext.extend or something in my application in order to modify the properties of the superclass (eg Ext.form.TextField).
2. I do not want to add maxLength, validationEvent, and valiadationDelay to all of the form fields in my app. I want to do it in one place and have all the associated fields inherit from the modification of the class.

If you know how to do this please advise with the code you used.

Thx for your help,

skirtle
15 Aug 2011, 4:55 PM
Are you using ExtJS 3 or 4? In ExtJS 4 the method Ext.extend() has largely been replaced with Ext.define() and Ext.form.TextField is now Ext.form.field.Text. If you're using ExtJS 3 then this isn't really the right forum.

Either way, have you tried this?


Ext.override(Ext.form.field.Text, {
maxLength: 100,
validationDelay: 1500,
validationEvent: 'blur'
});

I haven't tried it with these specific properties but as a general approach this usually works. A word of caution though, changing defaults globally like this can be a little risky if other classes rely on the original defaults.

bruce1058
24 Jul 2012, 7:07 AM
It should also be noted that validationDelay did not carry over to ExtJS 4.x.
I don't know what config item replaces it.