Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery DatePicker ReadOnly

When I make my datepicker read-only, I see that the user cannot type anything into the text box.

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

However, they can still change the value using the calendar. How can I hide the calendar so that users cannot change the date value?

I do not want to disable the datepicker since I need the value posted to the server upon form submit.

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

like image 398
Bob Avatar asked Oct 18 '11 18:10

Bob


People also ask

How do I make a date picker read only?

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

How do I make Datepicker textbox editable?

1 Answer. Show activity on this post. $('#start_date'). datetimepicker({timeFormat: "HH:mm:ss", dateFormat:"dd-mm-yy", constrainInput: false, maxDate: maxdate});

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.


1 Answers

I set the following beforeShow event handler (in the options parameter) to achieve this functionality.

beforeShow: function(i) { if ($(i).attr('readonly')) { return false; } } 
like image 134
Code Commander Avatar answered Sep 21 '22 16:09

Code Commander