Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a jqueryui datepicker

I have a jqueryui datepicker associated with a input text. When i make the input textbox readonly i dont want the datepicker to show up . Is that possible? I would be setting the readonly property to true or false from the code.

<script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    </script>



<div class="demo">

<p>Date: <input type="text" id="CompleteDate"> <input class="change" type="checkbox" name="chkBoxb" id="chkBoxb"> </p>

</div>


j$('#chkBoxb').click(function(){
   var paramChangeBoxes = j$('input:checkbox.change');

 if (j$(this).is(':checked')) {

  paramChangeBoxes.removeAttr('checked');
    j$('#chkBoxb').attr('checked', 'checked');

     j$('#CompleteDate').attr('readonly',false);
     j$("#CompleteDate").datepicker();


 }
 else
 {
  j$('#CompleteDate').attr('readonly',true);
 $( "#CompleteDate:not([readonly])"  ).datepicker();
 }

});

Updated the code

like image 560
Prady Avatar asked Feb 11 '11 08:02

Prady


People also ask

How do I disable date range picker?

DateRangePicker can be inactivated on a page, by setting enabled value as false that will disable the component completely from all the user interactions including in form post.

How do you make a datepicker not editable?

$("#my_txtbox"). attr( 'readOnly' , 'true' );

How do I unbind a datepicker?

You can try the enable/disable methods instead of using the option method: $("#txtSearch"). datepicker("enable"); $("#txtSearch"). datepicker("disable");

How do I disable UI datepicker trigger?

Datepicker has a built-in disable method for this you can use, which also disables the text input, like this: $("#datepicker"). datepicker("disable");


1 Answers

disable it like this:

$('#dateSelector').datepicker('disable');

and enable it like this:

$('#dateSelector').datepicker('enable');

Here's a working sample: http://jsfiddle.net/CG64h/8/

like image 110
BraveNewMath Avatar answered Oct 06 '22 10:10

BraveNewMath