Solved

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

Posted on 2016-07-15
4
64 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
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 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now