How do I change my textfield's emptyText field on the fly?
I've tried:
myTextField.emptyText = 'new empty text';
myTextField.emptyText = 'new empty text';
myTextField.applyEmptyText();
myTextField.emptyText = ['new empty text'];
myTextField.emptyText = ['new empty text'];
myTextField.applyEmptyText();
I realize that applyEmptyText()
is not listed in the API docs but I thought I'd give it a shot as this worked in previous versions. I've also read that one needs to add the brackets too.
I've printed myTextField
to the console and I see the emptyText
property set to what I want but the field in the browser is not updating.
Your first attempt should work as expected. However, as you can see in the source, there are certain criteria to be met before the placeholder is set. Your best bet is to place a breakpoint in the applyEmptyText
function and debug it.
applyEmptyText : function(){
var me = this,
emptyText = me.emptyText,
isEmpty;
if (me.rendered && emptyText) {
isEmpty = me.getRawValue().length < 1 && !me.hasFocus;
if (Ext.supports.Placeholder) {
me.inputEl.dom.placeholder = emptyText;
} else if (isEmpty) {
me.setRawValue(emptyText);
me.valueContainsPlaceholder = true;
}
//all browsers need this because of a styling issue with chrome + placeholders.
//the text isnt vertically aligned when empty (and using the placeholder)
if (isEmpty) {
me.inputEl.addCls(me.emptyCls);
}
me.autoSize();
}
}