Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Datepicker Function dynamically

I want to remove datepicker function depending on the dropdownlist selected value. I try the following codes, but it still shows the calendar when I put the cursor in the text box. Please give me a suggestion.

$("#ddlSearchType").change(function () {     if ($(this).val() == "Required Date" || $(this).val() == "Submitted Date") {         $("#txtSearch").datepicker();     } else {         $("#txtSearch").datepicker("option", "disabled", true);     } }); 

enter image description here

like image 341
TTCG Avatar asked May 24 '11 08:05

TTCG


People also ask

How do I remove Datepicker?

To destroy a datepicker in jQuery UI, we will be using destroy() method. jQuery UI destroy() method is used to remove the complete functionality of the datepicker(). Parameters: This method does not accept any parameters. Return values: This method simply returns the datepicker to its pre-initial state.

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 reinitialize Datepicker?

I would do it like this: $('#sv_pickup_date'). datepicker('destroy'). datepicker({ format: 'dd/mm/yyyy' , autoclose: true , startDate: '20/08/2018' , endDate: '24/08/2018' });


1 Answers

You can try the enable/disable methods instead of using the option method:

$("#txtSearch").datepicker("enable"); $("#txtSearch").datepicker("disable"); 

This disables the entire textbox. So may be you can use datepicker.destroy() instead:

$(document).ready(function() {     $("#ddlSearchType").change(function() {         if ($(this).val() == "Required Date" || $(this).val() == "Submitted Date") {             $("#txtSearch").datepicker();         }         else {             $("#txtSearch").datepicker("destroy");         }     }).change(); }); 

Demo here.

like image 74
Salman A Avatar answered Sep 24 '22 22:09

Salman A