Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'd like to add a calendar icon next to the Date text field (using pop-up widget currently) and trigger the pop-up widget with the icon. Same or similar to this jQuery function here:
http://jqueryui.com/demos/datepicker/#icon-trigger
Has anyone made this override to the Date field? Suggestions on where to look for the function to override and add the icon image to?
Thanks in advance.
Comments
Comment #1
jayboodhun CreditAttribution: jayboodhun commentedHi,
You can do this via jquery like this:
Comment #2
Binu Varghese CreditAttribution: Binu Varghese commentedMake the following 3 changes to date_popup.module :
1) Add 'showOn' => 'button'
2) Uncomment 'buttonImage' => base_path() . drupal_get_path('module', 'date_api') ."/images/calendar.png"
3) Uncomment 'buttonImageOnly' => TRUE
in line 320 (below)
$settings = array(
'changeMonth' => TRUE,
'changeYear' => TRUE,
'firstDay' => intval(variable_get('date_first_day', 0)),
// 'buttonImage' => base_path() . drupal_get_path('module', 'date_api') ."/images/calendar.png",
// 'buttonImageOnly' => TRUE,
'autoPopUp' => 'focus',
'closeAtTop' => FALSE,
'speed' => 'immediate',
'dateFormat' => date_popup_format_to_popup(date_popup_date_format($element), 'datepicker'),
'yearRange' => $year_range,
// Custom setting, will be expanded in Drupal.behaviors.date_popup()
'fromTo' => isset($fromto),
);
Cheers!
Comment #3
fcog CreditAttribution: fcog commentedI followed the instructions of Binu_Varghese. But the calendar icon only appears when you click on the date field. How can I show the icon on page load?
Comment #4
archnode CreditAttribution: archnode commentedI'd refrain from hacking the module code for obvious reasons. As the popup gets initialized when the input field first gets focus, it wouldn't be of much use anyway if you want to show the icon as soon as the page is displayed.
You can add an icon or text to trigger the display of the popup with the popup theme function:
The second step is to get the input field to get focus when the new element is clicked. Add a drupal behavior to do that:
Whats left to do is to add css for the new select button to fit your theme.
Comment #5
ashwinsh#1 Works for me. Thank you jayboodhun.
Comment #6
a.hover CreditAttribution: a.hover commentedInstead of using js to add the options (as the solution above) you can use the following form api php either in your custom form module or using hook_form_alter for an existing form:
In reply to fcog's question #3:
The date pop-up is only initialised once the field has been given focus. However, this is no use if you want the user to use a button to open the date picker first time, instead of clicking in the field and it appearing.
A quick and dirty way to force this type of field to be "initialised" on page load would be to include some javascript like:
This will loop through each of the date_popup fields and force a focus (and then blur so it doesn't remain focussed) on the offending text field. It's not a particularly elegant solution, but it does work and it allows you to still use the rest of the built in functionality of the field type "date_popup" instead of having to manually add the date-picker js as in solution #1.
Comment #7
littleindian CreditAttribution: littleindian commentedI solved this problem by doing below. #1 worked for me. But I just want to update the code of mine with some Drupal better code and correct implementation.
1. Add below code in your global.js file
2. if you want to do above changes for specific form then add below code in form alter or in custom form. Do not include in template.php because it will call every time.
3. Now, do bit css for image.
Reply if above code didn't work for you.
Comment #8
pbland CreditAttribution: pbland commentedI'm having the same issue as fcog in #3. I added the jQuery from #1, but my calendar image only appears when the input field receives focus. I tried #6 and #7, but the same issue. Has anyone overcome this issue?
Comment #9
santiwww CreditAttribution: santiwww commentedI've achieved this by using #4 with some slightly changes:
I'll describe the process followed.
First of all create a javascript file with the following code and save it wherever you want (good choice is a "js" folder within your theme's folder):
Then add the following code to your theme's template.php file changing the path in first line for your js file (the path should be relative to drupal root, see drupal_add_js()):
Apply css to the .date-popup-icon class to match your visual requirements.
Comment #10
soosa CreditAttribution: soosa commentedFirst of all i would like to express how stupid and poor decision that the jQuery UI date picker library developers made when they didn't provide an option to show the calendar icon or hide it on page display, this is simply stupid because from a usability perspictive, showing this image is much more usable than displaying it after clicking on some stupid text field, anyways, i came up with a very simple solution for this issue and i doesn't really need to alter or add anything except the following bunch of javascript code and a single line into wherever you're using the date_popup module:
First, write this javascript code into a file (name it m-datepicker.js or whatever) (note i am using an ID jQuery selector, not a CLASS, namely "edit-from-datepicker-popup-0", and "edit-to-datepicker-popup-0", you may change this as you wish):
The above code simply adds the missing calender icon and upon clicking on the image the rest will take place accordingly.
Finaly:
You need to add the above mentioned javascript file to your page using drupal_add_js, so it will look something like:
Comment #11
hugronaphor CreditAttribution: hugronaphor as a volunteer and at Acrosto for Dropsolid commentedIf anyone is interested in a contrib solution of the issue, have a look at Date Icon
Comment #12
earthangelconsulting CreditAttribution: earthangelconsulting commented#11 (dateicon module) is very useful, i highly recommend checking it out!
note: if you are using raw FAPI without the Fields module there are probably other points where you could set the type to 'dateicon' (see the readme for dateicon)... if using a date_combo with Fields, here's one way to set it... in the date_combo_process_alter hook:
and if you want to adjust the options (icon source etc.) when using dateicon, from the defaults in dateicon.module one way to do it is in a form after_build (using similar method to change the js settings as dateicon itself does)
eg:
Comment #13
DamienMcKennaComment #14
kmstf CreditAttribution: kmstf commented#14 solved the issue thanks to @goatvirus.
how can i apply these simple step below for imputmask feature work to code above?
THANKS A LOT!
Comment #15
steinmb CreditAttribution: steinmb as a volunteer commented