Robert Ross Robert Ross - 14 days ago 5
Javascript Question

Disabling datepicker on an input field

Cuurently I have an input field using

datepicker
. I am wondering how to disable the datepicker callendar popping up when I click on that field, since on my page I want the date option to be available only on certain conditions.

<input id="date" type="text " class="form-control datepicker" name="date" value="Click to select date">


I tried with :

$("#date").datepicker('disable');


And with :

$( "#date" ).datepicker( "disabled", true );


None worked.

Answer

One of the easiest way is to remove all the pointer events for that input field.

$("#date").css('pointer-events', 'none');

This will keep the data intact if you want.

And to re enable pointer events.

   $("#date").css("pointer-events", "");
Comments