Created
January 8, 2016 17:50
-
-
Save mglaman/1607b3668ffe92e4a771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function ($) { | |
| Drupal.behaviors.datePicker = { | |
| attach: function (context, settings) { | |
| var $fieldDate = $('form-item-attributes-field-date', context); | |
| var $fieldDateSelect = $fieldDate.find('select', context); | |
| var $fieldDateOptions = $fieldDate.find('option', context); | |
| // Insert datepicker div | |
| $('<div id="datepicker" />').insertBefore('.form-item-attributes-field-date'); | |
| // Get array of valid dates | |
| var validDates = []; | |
| $fieldDateOptions.each(function () { | |
| validDates.push($(this).text()); | |
| }); | |
| $("#datepicker").datepicker({ | |
| dateFormat: "dd/mm/yy", | |
| defaultDate: $fieldDate.find("option:selected").text(), | |
| beforeShowDay: function (date) { | |
| var string = jQuery.datepicker.formatDate('dd/mm/yy', date); | |
| return [validDates.indexOf(string) != -1] | |
| }, | |
| onSelect: function (dateText, inst) { | |
| var selected = $fieldDateOptions.filter(function () { | |
| return $(this).html() == dateText; | |
| }).val(); | |
| $fieldDateSelect.val(selected).trigger("change"); | |
| } | |
| }); | |
| } | |
| }; | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment