Call function after choosing date

0

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 function validator is not called.

Does anyone know how I can do this?

    
asked by anonymous 01.08.2016 / 13:37

2 answers

2

That may be what you need

$("#SeuInput").on("change", function(){
  alert("Mudou o valor");
  suafuncaoaqui();
});
    
01.08.2016 / 14:57
0

I think 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, pick 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;
    }
    
01.08.2016 / 15:48