Quantcast
Channel: SCN: Message List - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 8124

Re: Validating Date in Controller of SAPUI5

$
0
0

Hi,

 

Just modified your code as below: Try this,

 

View

------

var oLb_chkdate =  new sap.ui.commons.Label({text:"Date of Check"});

   var oTf_prdate =  new sap.ui.commons.DatePicker({id: 'tf_chkdate',

   change : oController.onChange}

   );

      oLb_chkdate.setLabelFor(oTf_prdate);

 

 

----------------------------------

 

Controller

-------------

 

onChange: function(oEvent){

   

    var today = new Date();

         var dd = today.getDate();

         var mm = today.getMonth()+1; //January is 0!

  

  

         var yyyy = today.getFullYear();

         if(dd<10){

             dd='0'+dd;

         }

         if(mm<10){

             mm='0'+mm;

         }

         var today = yyyy+'/'+mm+'/'+dd;

        

     if(oEvent.getParameter("invalidValue")){

   oEvent.oSource.setValueState(sap.ui.core.ValueState.Error);

   }else{

  

   var inpDt = sap.ui.getCore().byId('tf_chkdate').getValue();

   var dateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "yyyy/MM/dd"});

         

          var inputDate = dateFormat.format(new Date(inpDt));

   alert(inputDate);

   if ( inputDate > today)

   oEvent.oSource.setValueState(sap.ui.core.ValueState.Error);

   else

   oEvent.oSource.setValueState(sap.ui.core.ValueState.None);

   }

   

    }

    } );

 

 

 

hope this helps,

 

 

Regards,

Kiran


Viewing all articles
Browse latest Browse all 8124

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>