Solved

datepicker - prevent a textbox click from invoking the pop-up calendar

Posted on 2016-07-15
4
83 Views
Last Modified: 2016-07-15
I have a datepicker control that is implemented via jQuery.

When you click on the text box control OR the calander icon image, the calendar pops up.

I want to make it so that ONLY the calendar icon image is clickable.  Clicking on the text box should NOT invoke the calendar popup.

I tried setting "disabled" to true on mouseenter, but then I don't seem to be able to click the calendar image icon when I do that.

Here is a jsfiddle:

Sample 1:
date picker popup



Sample 2:
Here is the control as it currently functions

Notice that in Sample 2, clicking on the "clear" command DOES clear out the value of the input tag, but then for some reason the calendar pop up invokes.  I don't want the calendar to pop-up.  I just want to clear the text input value.

But when I click elsewhere to make the calendar pop up go away --  the date value comes back!!!!
0
Comment
Question by:knowlton
  • 2
  • 2
4 Comments
 
LVL 42

Expert Comment

by:zephyr_hex (Megan)
ID: 41713453
Can you share what your end goal is with preventing the pop up to show when the textbox is clicked?  What are you trying to achieve or prevent?
0
 
LVL 5

Author Comment

by:knowlton
ID: 41713461
Desired functionality:

When the user clicks on the "text box" portion, nothing happens.

When the user clicks on the "calendar icon" (to the right of the text box) the calendar pops-up.

When the user clicks on the "clear" button, the date value is set to ""
0
 
LVL 42

Accepted Solution

by:
zephyr_hex (Megan) earned 500 total points
ID: 41713525
With the following HTML

<input type="text" id="datepicker">
<input type="button" id="btnClear" value="Clear">

Open in new window


You can disable the calendar on the textbox and clear the date using JQuery:

$("#datepicker").datepicker({
  showOn: "button",
  buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
  buttonImageOnly: true
});

$('#btnClear').click(function() {
  $("#datepicker").val("");
});

Open in new window


Here is a Fiddle Demo
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 41713591
I am going to see if I can take your fiddler example and reskin it to look like Sample 2.

Thank you.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question