The question is published on by Tutorial Guruji team.
I have a form. And lots of textfields
in it. I use allowBlank
property not to allow user to left the field blank and blankText
to define custom “blank error” text.
{ xtype: 'textfield', fieldLabel: 'Surname', name: 'person_surname', allowBlank: false, blankText: 'Please fill "Surname" field', },
My question is:
Is there a way to use Ext.form.field.Text’s object property inside of another propery of the same object?
Something like:
{ xtype: 'textfield', fieldLabel: 'Surname', name: 'person_surname', allowBlank: false, blankText: 'Please fill "' + fieldLabel + '" field', },
(doesn’t work)
or:
{ xtype: 'textfield', fieldLabel: 'Surname', name: 'person_surname', allowBlank: false, blankText: 'Please fill "' + this.fieldLabel + '" field', },
(doesn’t work either)
Update:
For example in minLengthText
property I can use template driven text like ‘The minimum length for this field is {0}’, which takes minLength
property value of the same object.
I repeat: I use ExtJS’s object initialization method whith object literal syntax like:
{ xtype: 'textfield', fieldLabel: 'Surname', name: 'person_surname', allowBlank: false, blankText: 'Please fill "Surname" field', },
This syntax is very neat, using another syntax is not welcome here.
Answer
try adding listener to your form if you don’t want to rewrite your code
example
listeners : { render : function(){ Ext.each(form.items.items,function(fld,idx){ if(fld.getXType()=='textfield'){ fld.blankText = fld.fieldLabel; } }); } }