Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS/Sencha - Add button to DateField popup, to clear date

I have a DateField:

  editor : new Ext.form.DateField({ /*Ext.ux.form.Custom*/
      allowBlank: true,
      format: 'm/d/Y',
      width : 120,
      enableKeyEvents: true,
      listeners: {
              'keydown' : function (field_, e_  )  {
                field_.onTriggerClick();
                e_.stopEvent();
                return false;
          },
              'focus' : function (field_  )  {
                field_.onTriggerClick();
                e_.stopEvent();
                return false;
          }
      }
  })

Editing of this field is disabled. On any edit, it shows popup, so any clear of date is impossible. Is there a way to add to popup something like button Today, but meaning Clear, after which date in this field will be resetted to 00.00.00?

Thanks.

like image 304
publikz.com Avatar asked Nov 19 '11 01:11

publikz.com


1 Answers

Try something like this:

{
    xtype: 'datefield',
    onTriggerClick: function() {
        Ext.form.DateField.prototype.onTriggerClick.apply(this, arguments);
        var btn = new Ext.Button({
            text: 'Clear'
        });
        btn.render(this.menu.picker.todayBtn.container);
    }
}

It's very dependent on implementation, but it works. And you must flag it that way it won't render another clear button every time you click the trigger.

like image 54
Krzysztof Avatar answered Sep 22 '22 21:09

Krzysztof