Calling function after choosing date

Asked

Viewed 863 times

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 don’t write directly to input and just click on datepicker, the Validator function is not called.

Does anyone know how I can do it?

  • We need to see your datepicker code. It’s either a plugin or it’s HTML5 native?

2 answers

2


That might be what you need

$("#SeuInput").on("change", function(){
  alert("Mudou o valor");
  suafuncaoaqui();
});

0

I believe that 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;
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.