Making a jQuery UI DatePicker Read Only
To make this post clear, by ReadOnly I mean really read only, no input allowed whatsoever.
DatePicker default behavior
This one seemed easy at first but it isn't just because by design, setting the input textbox to readonly, the widget will understand it as if we just wanted to limit the user to choose a date from the popup, disallowing any input text.
What I want here is to block any way for the user to change the textbox value, either from the calendar popup or by direct input on the textbox.
Option 1: Disable Textbox
The good | The bad |
Works! | Grays out the control to make it look disabled |
This would be a quick solution by just disabling the textbox but it kind of shades the control, and I want it to display its value with the same appearance as the other textboxes. Not approved!
Option 2: Bend the control
This DatePicker widget has a lot of options, we just have to find a way to use them in our favor to achieve this "unsupported" behavior.
<input type="text" id="txtDate" readonly="readonly" />
<script type="text/javascript">
$(document).ready(function () {
$('#txtDate').datepicker(
{
beforeShow: function (input, inst)
{ inst.dpDiv = $('<div style="display: none;"></div>'); }
});
});
</script>
What did I do?
On the textbox you can see that I made it read-only, but as I said, this alone still lets the user change the date from the calendar popup. To block the calendar popup, I'm replacing it with an empty DIV
element, and to avoid unhandled complications, I'm styling it as display: none
.
With this workaround, the DatePicker still thinks it is showing the popup but in fact nothing happens.
This is kind of tricky but is pretty easy to do and works very well on all browsers.
My recommendation to the jQuery UI team
This would be so much easier if we need only pass something like: showOn: "never"
.
发表评论
Well I really liked studying it. This subject offered by you is very effective for proper planning.
Thanks a lot for the article.Really looking forward to read more. Fantastic.
Really informative article post.Much thanks again. Want more.
You ave made some good points there. I looked on the internet for additional information about the issue and found most individuals will go along with your views on this website.
Keep it up!. I usually don at post in Blogs but your blog forced me to, amazing work.. beautiful A rise in An increase in An increase in.
Pretty! This was a really wonderful article. Thank you for supplying these details.
When some one searches for his vital thing, thus he/she wishes to be available that in detail, so that thing is maintained over here.
Thanks for sharing, this is a fantastic article post. Want more.
Really appreciate you sharing this article.Really thank you! Fantastic.
Im thankful for the article post.Thanks Again. Cool.
Thank you ever so for you post.Thanks Again. Fantastic.
J aadmire cette photo neanmoins j aen ai deja entendu certains nouveaux de meilleures qualifications?
I think this is among the most vital info for me.
Way cool! Some extremely valid points! I appreciate you writing this write-up and also the rest of the site is also very good.
You have brought up a very great points , appreciate it for the post.
very good publish, i actually love this web site, keep on it
Very good article post.Really thank you!
Terrific paintings! That is the type of information that should be shared around the net. Shame on Google for not positioning this submit higher! Come on over and visit my site. Thank you =)
Im obliged for the post.Thanks Again. Fantastic.
I value the article.Really thank you! Fantastic.
There as certainly a great deal to learn about this issue. I love all of the points you have made.
Loving the info on this internet site , you have done great job on the content.
Just wanna admit that this is handy , Thanks for taking your time to write this.
pretty useful material, overall I imagine this is well worth a bookmark, thanks
not operating correctly in Explorer but looks
Im grateful for the blog post.Thanks Again. Really Cool.
Your means of explaining all in this piece of writing is genuinely fastidious, all can without difficulty be aware of it, Thanks a lot.
There is apparently a bundle to identify about this. I suppose you made some good points in features also.
Im grateful for the article post.Really thank you! Great.
Way cool! Some very valid points! I appreciate you writing this article and the rest of the site is also very good.
There is clearly a bundle to know about this. I assume you made certain nice points in features also.
You have made some good points there. I looked on the net for additional information about the issue and found most individuals will go along with your views on this website.
to discover his goal then the achievements will be
Wow! Thank you! I constantly needed to write on my site something like that. Can I implement a portion of your post to my site?
What as up colleagues, I am for a second time here, and reading this post related to SEO, its also a nice piece of writing, thus keep it up.
Wow, great blog.Thanks Again. Fantastic.
Way cool! Some very valid points! I appreciate you writing this write-up and also the rest of the site is also really good.
interest. If you have any suggestions, please let me know.
very nice post, i certainly love this web site, keep on it
Many A Way To, Media short term loans kansas
that i suggest him/her to visit this blog, Keep up the
you download it from somewhere? A design like yours with a few
You ave made some good points there. I looked on the internet to find out more about the issue and found most individuals will go along with your views on this website.
Only wanna comment that you have a very decent website , I like the style and design it actually stands out.
Very good post! We are linking to this great post on our website. Keep up the good writing.
Im thankful for the post.Really thank you! Great.
Wow! I cant believe I have found your weblog. Extremely useful information.
Thanks for the article post.Thanks Again. Really Cool.
What a joy to find smooene else who thinks this way.
Yayoo.fr mail tirage gratuit tarot de l amour