Call function after choose Date

Good Morning,

I have an input text with a datepicker. The input has a validator function that changes the color of the input as the text is right or wrong.

But in this case as I do not write directly in the input and just click on the datepicker, the validator function is not called.

Does anyone know how I can do this?

Author: M_b_85, 2016-08-01

2 answers

May be what you need

$("#SeuInput").on("change", function(){
  alert("Mudou o valor");
  suafuncaoaqui();
});
 2
Author: Marcelo, 2016-08-01 12:57:02

I believe this would solve your case:

 $( "#input" )
        .datepicker({
         //regras do datapicker aqui
 })
 .on( "change", function() {
     //this é o elemento input, o valor seria: this.value
     suaFuncaoDeValidacaoAqui(this);
  });

Or if you prefer, take the date, in the same function:

 .on( "change", function() {
     suaFuncaoDeValidacaoAqui(getDate(this));
  });

 function getDate( element ) {
          var date;
          try {
            date = $.datepicker.parseDate( dateFormat, element.value );
          } catch( error ) {
            date = null;
          }
      return date;
    }
 0
Author: Ivan Ferrer, 2016-08-01 13:48:24