Skip to content

Instantly share code, notes, and snippets.

@xiexiao
Created July 25, 2014 03:40
Show Gist options
  • Save xiexiao/00cecaf3c26deaa96812 to your computer and use it in GitHub Desktop.
Save xiexiao/00cecaf3c26deaa96812 to your computer and use it in GitHub Desktop.
a extjs datefield with a clear button
{
xtype: 'datefield',
onTriggerClick: function () {
var dt1 = this;
Ext.form.DateField.prototype.onTriggerClick.apply(dt1, arguments);
if (Ext.isEmpty(dt1.clearBtn)) {
this.clearBtn = new Ext.Button({
text: 'Clear',
handler: function () {
dt1.setValue("");
dt1.picker.hide();
dt1.collapse();
}
});
dt1.clearBtn.render(dt1.picker.todayBtn.container);
}
},
itemId: 'endDt',
format: 'Y-m-d H:i:s',
labelWidth: 68,
value: '',
width: 218,
fieldLabel: 'EndTime',
listeners: {
select: function (field, value, eOpts) {
var temp = Ext.Date.add(new Date(value), Ext.Date.HOUR, 23);
temp = Ext.Date.add(new Date(temp), Ext.Date.MINUTE, 59);
temp = Ext.Date.add(new Date(temp), Ext.Date.SECOND, 59);
field.setValue(temp);
}
}
},
@AllenHom
Copy link

why the clearBtn handler can't be fired?

@Infarch
Copy link

Infarch commented May 11, 2016

why the clearBtn handler can't be fired?

Because "ownerCt" should be specified as well:

this.clearBtn = new Ext.Button({ text: 'Clear', handler: function(){ dt1.setValue(''); dt1.picker.hide(); dt1.collapse(); }, renderTo: dt1.picker.todayBtn.container, ownerCt: dt1.picker });

@hu-qi
Copy link

hu-qi commented Oct 14, 2020

why the clearBtn handler can't be fired?

Because "ownerCt" should be specified as well:

this.clearBtn = new Ext.Button({ text: 'Clear', handler: function(){ dt1.setValue(''); dt1.picker.hide(); dt1.collapse(); }, renderTo: dt1.picker.todayBtn.container, ownerCt: dt1.picker });

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment