Anusha Swaminathan
Anusha Swaminathan

Reputation: 69

Remove emptyText on focus

I am currently working with ExtJS. I have a textfield which has an emptyText set as a config. "emptyText : 'Please enter'"

When I click on it, it doesn't disappear. Only if I enter something, it goes. Is there any way in which this can be done?

Upvotes: 1

Views: 1393

Answers (2)

vikas
vikas

Reputation: 939

It should work for xtype:'textfield'. Can you provide more details about your attempt? I did not get any issue. Here is the sample code.

var form = new Ext.form.FormPanel({
    items: [{
        name: 'Test',
        xtype:'textfield',
        emptyText:'Empty Text',
    }]
});

Upvotes: 0

incutonez
incutonez

Reputation: 3331

I don't really like this solution, but I've come up with this (viewable here):

Ext.application({
  name : 'Fiddle',

  launch : function() {
    Ext.create('Ext.form.Panel', {
      title: 'Contact Info',
      width: 300,
      bodyPadding: 10,
      renderTo: Ext.getBody(),
      items: [{
        xtype: 'textfield',
        name: 'name',
        fieldLabel: 'Name',
        allowBlank: false,  // requires a non-empty value,
        emptyText: 'blah',
        originalEmptyText: 'blah',
        listeners: {
          focus: function() {
            this.emptyText = ' ';  // if you set it to empty string, it doesn't work
            this.applyEmptyText();
          },
          blur: function() {
            this.emptyText = this.originalEmptyText;
            this.applyEmptyText();
          }
        }
      }]
    });
  }
});

Upvotes: 1

Related Questions