cancel
Showing results for 
Search instead for 
Did you mean: 

How to show Today button on sap.m.DatePicker in UI5

MikeB
Contributor
0 Kudos

UI5 has a date picker controller sap.m.DatePicker, the problem is that this controller by default has no Today button, which will automatically select today's date.

Is there any way to add Today-button to sap.m.DatePicker?

Accepted Solutions (1)

Accepted Solutions (1)

MikeB
Contributor

As of 1.95.0, there is no need to invent a wheel, there is a standard property called showCurrentDateButton.

Sample, please, have a look on the "DatePicker with non-working days - 05.11.2015 - 25.11.2015 and with shortcut for today" case.

For those, who is below the 1.95.0, the Konchada's answer is a great solution!

Answers (2)

Answers (2)

konchada_saikrishna
Active Participant

Hi All,


We have same requirement and on search came to this old thread, however following some of the other experts advise we extended and added the today button as below.

For this we extended DatePicker, Calender & Calender renderer. and with a new attribute "showTodayButton" on date picker, so this button is displayed only where requested.

Calender.js

CalenderRenderer.js

DatePicker.js-->_createPopupContent

Hope this helps you guys.

former_member445109
Active Participant
0 Kudos

Hello Konchada Sai Krishna

I have same requirement, could you please post full code of renderer and _ceatePopupContent .

Thank you in Advance.

Best Regards

Srikanth G

smarchesini
Active Contributor

Hi MIke,
there are many method to do that, but custom.
Maybe the easily one is :

View

<DatePicker id="TodayPicker" value="{yourbinding}" />
<Button text="Today" press="onPress"/>

Controller

onPress : function ( oEvent ) {
 this.getView().byId("TodayPicker").setDateValue(new Date());
}


Regards,
Sebastiano

MikeB
Contributor
0 Kudos

Hi Sebastiano,

thanks for the tip, a separate button will definitely work, but the key idea to add such button into sap.m.DatePicker.

smarchesini
Active Contributor
0 Kudos

It is a nice advise for SAPUI5 team !
Someday maybe it'll be able 🙂