Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-07-15
4
Medium Priority
?
264 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 44

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:Tom 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 44

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 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:Tom 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

704 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