PDA

View Full Version : Disabling or hiding DatePicker today button [2.0.1]



halkon_polako
3 Feb 2008, 11:54 AM
Hi, as an example that how we can disabling and/or hiding the today button, we can use:


Ext.override(Ext.DatePicker,{
onRenderOriginal: Ext.DatePicker.prototype.onRender,
onRender: function(container, position){
this.onRenderOriginal(container,position);
this.eventEl.addKeyListener(Ext.EventObject.SPACE,Ext.emptyFn, this);
this.todayBtn.hide(); //HIDE BUTTON. PUT YOUR LOGIC HERE
}
});

In the case shown, the button is hidden. We can hide it or disable it taking in account the rules that we want, maybe, if today is out from the max/min values setted on DatePicker.
I let to you to implement the logic ;), just I show a place.

brian.moeskau
9 Jul 2008, 10:53 PM
This is now supported in Ext (for 2.2+). Please see details here (http://extjs.com/forum/showthread.php?p=193215#post193215).

DannyMeister
29 Oct 2008, 11:06 AM
I am still using 2.0.1, so I can't use the new showToday config in 2.2. I tried using this example, but it does not work, because todayBtn is not a variable defined in the DatePicker class. It is a local variable inside of the original onRender (which becomes onRenderOriginal) so it is out of scope in the overridden onRender.

halkon_polako
30 Oct 2008, 12:04 AM
Hi... since todayBtn is a variable 'autodefined' in the DatePicker class, I mean, that it is not defined explicitely.
It is defined by an assignament inside the onRender method (as you can see... this.todayBtn=....), so if in your override onRender you first call onRenderOriginal method, the variable todayBtn becomes created and available.

DannyMeister
30 Oct 2008, 5:46 AM
Maybe I have a slightly different version of Ext? This is what I see in the original DatePicker onRender:




var today = (new Date()).dateFormat(this.format);
var todayBtn = new Ext.Button({
renderTo: this.el.child("td.x-date-bottom", true),
text: String.format(this.todayText, today),
tooltip: String.format(this.todayTip, today),
handler: this.selectToday,
scope: this
});

It does not assign to this.todayBtn. Later when I try to access this.todayBtn my browser gives me an error. I was told that we are using version 2.0.1 here at work, though the top line only says
Ext JS Library 2.0

halkon_polako
30 Oct 2008, 11:37 PM
Well... I just downloaded Ext2.0.1 to verify this, and this is the code inside DatePicker:


var today = (new Date()).dateFormat(this.format);
this.todayBtn = new Ext.Button({
renderTo: this.el.child("td.x-date-bottom", true),
text: String.format(this.todayText, today),
tooltip: String.format(this.todayTip, today),
handler: this.selectToday,
scope: this
});

So... I think you are not using 2.0.1.
If the top line of your source says Ext 2.0, then you are using Ext 2.0 not 2.0.1, so this patch can't be work.
Try to go the the latest version 2.2 or 2.0.2 or override the full original onRender() method ...