There are no secrets to success. It is the result of preparation, hard work, and learning from failure.

Thursday, 9 June 2016

Date Validation

Click here and follow my SAP UI5/FIORI snippets and information Page
I have done below "DATE VALIDATION",here you can't selected the future's date and past's date.you can select only today's date.Go through it and please let me know in case of any issue/doubt.


Paste below lines in view.

<DatePicker id="Date_iD" visible="true" displayFormat="dd MMM yyyy" valueFormat="dd.MM.yyyy" change="Day_select"/>

  Paste below lines in controller.

// If you select date then this method will fire.............  
Day_select:function()
 {
var TodaysDate=new Date();
var MOnTh=TodaysDate.getMonth();
var YEaRs=TodaysDate.getFullYear();
var DAte=TodaysDate.getDate();
var value=this.byId("Date_iD");
var selectDate=value.getDateValue();
var MOnTh1=selectDate.getMonth();
var YEaRs1=selectDate.getFullYear();
var DAte1=selectDate.getDate();
var date=DAte1-DAte;
var month=MOnTh1-MOnTh;
var year=YEaRs1-YEaRs;
var total=date+month*30+year*365;
if(total>0)
{
sap.m.MessageToast.show("Date can't be in future");
value.setDateValue(TodaysDate);
return;
}
if(total<0)
{
sap.m.MessageToast.show("Date can't be in Past");
value.setDateValue(TodaysDate);
return;
}
}

Result


No comments:

Post a Comment