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.
Hi,
I'm doing a custom module using the date_popup form element, I need to set up a restriction on the calendar popup minDate jquery attribute but the #datepicker_options configuration array is not passed to the element configuration function. Here is my element
$form['event_start_date'] = array(
"#title" => t("Select the event start date"),
"#type" => "date_popup",
'#datepicker_options' => array('minDate'=>"0"),
);
I debug up to the part where the configuration array is merge with the incoming one but the datepicker_options array is empty in the line 332 of the date_popup module.
$settings = $element['#datepicker_options'] + array(
'changeMonth' => TRUE,
'changeYear' => TRUE,
'autoPopUp' => 'focus',
'closeAtTop' => FALSE,
'minDate' => '1',
'speed' => 'immediate',
'firstDay' => intval(variable_get('date_first_day', 0)),
//'buttonImage' => base_path() . drupal_get_path('module', 'date_api') ."/images/calendar.png",
//'buttonImageOnly' => TRUE,
'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),
);
Thank you for your help
Julian Mancera
Comments
Comment #1
Sylvain Lecoy CreditAttribution: Sylvain Lecoy commentedSeems also that the 'fromTo' value is not doing anything, and in the code, the $fromto variable is never assigned. Thus the 'fromTo' value is always FALSE by default;
I don't know either how to use the 'date_popup' element in a custom module form.
Any help would be appreciated!
Comment #2
Sylvain Lecoy CreditAttribution: Sylvain Lecoy commentedIt is actually because the component is created on user focus(). See date_popup.js.
To fix it, I had to manually create the component through .datepicker in a custom script, then adding the class date-popup-init to avoid recreating it, then applies my custom settings.
It really mimics the javascript furnished by date popup module but it was the only way to overrides default behaviour.
Comment #3
haggins CreditAttribution: haggins commentedAnother method is to overwrite
#process
callback of your date_popup field. There you can overwrite the process function for the date part which itself passes datepicker settings to date_popups.js which passes it to .datepickerSee
date_popup_element_process()
anddate_popup_process_date_part()
how the default processes looks like.If you also want to set function properties like onSelect or onClose you need your own script, ie:
Comment #4
thipa CreditAttribution: thipa commentedThis code is not working when validation fail. Any fix would be helpful?
datepicker_settings.onSelect = function(dataText) {
alert('selected: ' + dataText);
};
Comment #5
haggins CreditAttribution: haggins commentedCan you please provide more information about what exactly is not working and how to reproduce the issue?
Comment #6
thipa CreditAttribution: thipa commentedI want to control position of pop up calendar. so i reproduce this with beforeShow option. Every thing works fine as expected. But when the form validation fails, that beforeShow isn't call. when i log this value in console, it prints 'undefined'. Thanks.
Comment #7
haggins CreditAttribution: haggins commentedDo you mean after form submission with validation error the beforeShow event doesn't work anymore? If so: is it important whether the validation error occurs on the date field or not?
Comment #8
thipa CreditAttribution: thipa commentedThanks.It fixed, i changed the js file called place, then it works.
Comment #9
Malakof CreditAttribution: Malakof commentedHello, sorry to bring this thread back to life, but the code above is not working in my case. I have the following drupal behavior at the top of my script, and a datepicker in a webform. I want to be notified when a date is selected in the datepicker. In my form template i drupal_add_js a js starting with :
The behavior attach code gets called only once, after the page gets loaded, never reach the alert: of course the datepicker is not present in the div at this time. When the datepicker icon is clicked, the datepicker gets injected but the behavior is not called and so nothing happen. None of the alert in the code above are shown.
Note i change datePopup to date_popup who was undefined in my sources, but no matter what there is no date related in Drupal.sttings on the debugger.
Any clues ? Thanks.
Comment #10
haggins CreditAttribution: haggins commentedTry Drupal.settings.datePopup instead of Drupal.settings.date_popup
Comment #11
bluetegu CreditAttribution: bluetegu commentedI used hook_date_popup_process_alter for that, as settings tends to merge nicely.