我正在使用drupal 7模块日期(date_popup)。我有2个datepickers。我需要在“onSelect”事件上的第二个datepicker上更新minDate,方法是单击第一个。它适用但仅适用于第二次点击。如果我点击第一个日期选择器并选择日期没有任何反应,minDate不会更新。当我第二次选择时效果很好。为什么我的第一次点击不起作用?
这是我的模块的datepicker init php代码。
<?php
$form['leave'] = array(
'#type' => 'date_popup', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
'#title' => t('Leave'),
'#default_value' => date('Y-m-d'),
'#date_format' => $format,
'#required' => TRUE, // Added
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#date_year_range' => '-3:+3', // Optional, used to set the year range (back 3 years and forward 3 years is the default).
'#datepicker_options' => array(
'changeMonth' => false,
'changeYear' => false,
'altField' => '#edit-leave-alt',
'showOtherMonths' =>true,
'selectOtherMonths' =>false,
'altFormat' => 'D, M d, yy',
'minDate' => 0,
), // Optional, as of 7.x-2.6+, used to pass in additional parameters from the jQuery Datepicker widget.
'#attributes' => array('readonly' => 'readonly')
);
$form['leave'] = array(
'#type' => 'date_popup', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
'#title' => t('Leave'),
'#default_value' => date('Y-m-d'),
'#date_format' => $format,
'#required' => TRUE, // Added
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#date_year_range' => '-3:+3', // Optional, used to set the year range (back 3 years and forward 3 years is the default).
'#datepicker_options' => array(
'changeMonth' => false,
'changeYear' => false,
'altField' => '#edit-leave-alt',
'showOtherMonths' =>true,
'selectOtherMonths' =>false,
'altFormat' => 'D, M d, yy',
'minDate' => 0,
), // Optional, as of 7.x-2.6+, used to pass in additional parameters from the jQuery Datepicker widget.
'#attributes' => array('readonly' => 'readonly')
);
?>
这是我的js代码
(function($) {
Drupal.behaviors.ifly_search = {
attach: function (context, settings) {
$("#edit-leave-datepicker-popup-0").datepicker({
onSelect: function(date,param) {
var data = new Date(param.currentYear, param.currentMonth, param.currentDay);
$("#edit-return-datepicker-popup-0").datepicker("option", "minDate", data).val(date);
},
});
}
};
})(jQuery);
答案 0 :(得分:0)
只是为了充实我的评论。试试这个:
(function($) {
Drupal.behaviors.ifly_search = {
attach: function (context, settings) {
$("#edit-return-datepicker-popup-0").datepicker({minDate: new Date()});
$("#edit-leave-datepicker-popup-0").datepicker({
onSelect: function(date,param) {
var data = new Date(param.selectedYear, param.selectedMonth, param.selectedDay);
$("#edit-return-datepicker-popup-0").datepicker("option", "minDate", data).val(date);
},
});
}
};
})(jQuery);
答案 1 :(得分:0)
Skarist,非常感谢你! 这是工作代码:
Drupal.behaviors.ifly_search = {
attach: function (context, settings) {
$("#edit-leave-datepicker-popup-0").datepicker({
onSelect: function(date,param) {
var data = new Date(param.selectedYear, param.selectedMonth, param.selectedDay);
$("#edit-return-datepicker-popup-0").datepicker({minDate: data}).val(date);
$("#edit-return-datepicker-popup-0").datepicker("option", "minDate", data).val(date);
},
});
}
};