I'm trying to limit de date range that datapicker popup allows to select on a date field. I'have a custom module where I drive all my modifications and "hook_alters". I call a javascript file on a hook_init with many modifications here and there and all perform as expected.
Drupal.behaviors.datepickerMaxDate = {
attach: function (context, settings) {
var form = $('form#nodetype-node-form');
form.find('#edit-field-date-oferta-und-0-value-datepicker-popup-0')
.datepicker({ minDate: 0, maxDate: "+7D" });
}
};
When I place that function on the module js (added on hook_init via drupal_add_js) it breaks many module JS as fivestars or jcarousel. But when I place exactly the same function on my theme's js file it works and the other modules javascript also works as expected.
I'm not very proficient with JS and learning very fast, may someone advise me why it works on my theme but not on my module??
Thanks :-)))
Comments
Comment #1
jorditr commentedI finally found that even that solution collided on other node types with the wysiwyg editor. I realized that it was colliding on all content types forms except on the ones that had the date widget that I was trying to modify and I understood that I had to verify that the field existed. Thanks to that now it works and I've been able to return that JS function to the module js file (not in theme's template file).
For documenting that issue for others that could find the same trouble, the code is:
I'm not expert enough to know if it's a good solution or not. Is someone with a better understing wants to suggest something new feel free to writte it down!
Thanks to the maintainers of such an impressive module :-)
Comment #2
nightlife2008 commentedI solved this problem using the HOOK_date_popup_process_alter(), which is run AFTER the element has been processed, to add the #datepicker_options array.
After adding the options, I just reprocess the element with the proper options set.
Works like a charm!
Comment #3
fox mulder commentednightlife2008: Thanks for your help!
Comment #4
berramou commentedhow can i add minDate in HOOK_date_select_process_alter()
thanks .
Comment #5
nishat ahmad commented