Date Picker opens itself when it changes neighbor input

Asked

Viewed 193 times

1

Good morning, I have the following code:

var maxDate = new Date();
maxDate.setDate( maxDate.getDate() + 364);

$(".dtpBloqueio").datepicker( {
    numberOfMonths: 2,
    dateFormat: 'dd/mm/yy',
    maxDate: maxDate
});

when a select input is changed that is within the same as the date input, if any, maxDate is set as today.

<table>
    <tr>
        <td>
           <select name="datasLocalizaSv" id="listaDatasLocalizaSv"/>
        </td>   
        <td>
          <input id="dataComeco" name="dataComeco" class="dtpBloqueio"/>
        </td>
    </tr>
</table>

$(".dtpBloqueio").datepicker("change", { maxDate: new Date() } );

Only every time I change the information in select the datapicker opens itself in the first input, only it opens blank, as if it had used the "refresh".

How can I make the datepicker not open alone when I change something on his side?

  • I don’t quite understand your problem. You can take a look at this jsFiddle: http://jsfiddle.net/3ox5ax7z/ and adapt by explaining how you want it to work?

2 answers

1

I believe your error is precisely in the date-changing code. I searched the documentation and there is no such option change, then I think this is generating some event that is interpreted as a click. Try to replace this code with something like this:

$( ".dtpBloqueio" ).datepicker( "option", "maxDate", new Date() );
  • When I put this code, it gives the following error:Uncaught Typeerror: Cannot read Property 'apply' of Undefined

1

I managed to sort it out like this:

$( ".dtpBloqueio" ).datepicker('destroy');

and then I created again the datepicker:

$(".dtpBloqueio").datepicker( {
    numberOfMonths: 2,
    dateFormat: 'dd/mm/yy',
    maxDate: new Date()
});

Browser other questions tagged

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