4
我正在使用Bootstrap 3 Datetimepicker,我的理念是隻有在第二次點擊後它纔會觸發。日期選擇器組在運行時創建。Bootstrap 3 Datetimepicker在第二次點擊時觸發
這是我的代碼(的Drupal 7):
custom.module file
$values = isset($form_state['multistep_values']['second_step']) ? $form_state['multistep_values']['second_step'] : array();
$form['second_step']['departure_date'] = array(
'#theme_wrappers' => array(), // to temove drupal default wrapper
'#type' => 'textfield',
'#default_value' => isset($values['departure_date']) ? $values['departure_date'] : NULL,
'#attributes' => array(
'class' => array('form-control dtpicker'),
'readonly' => true
),
'#prefix' => '<div class="col-sm-8"><div class="form-group"><div class="input-group date" id="datetimepicker1">',
'#suffix' => '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></div></div>',
);
generated output
<div class="col-sm-8"><div class="form-group"><div class="input-group date" id="datetimepicker1"><input class="form-control dtpicker form-text" readonly="1" id="edit-departure-date" name="departure_date" value="" size="60" maxlength="128" type="text"><span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></div></div>
custom.js file
(function($) {
Drupal.behaviors.custom = Drupal.behaviors.custom || {};
Drupal.behaviors.custom.attach = function(context) {
Drupal.custom.datetimepicker(context);
};
Drupal.custom = Drupal.custom || {};
/*
* Datetimepicker behavior
*/
Drupal.custom.datetimepicker = function(context) {
$(document).on('click', '#datetimepicker1', function() {
$(this).datetimepicker({
format: 'Y-MM-D HH:mm',
allowInputToggle: true,
ignoreReadonly: true,
showClear: true,
showClose: true,
showTodayButton: true
});
});
};
}(jQuery));
有何想法?
我試圖初始化,然後設置的值,如:
$(this).datetimepicker();
$(this).datetimepicker({ ... });
在焦點
或init第一和的onClick設置的選項。他們兩人仍然在第二次點擊。
它的工作綁定額外的點擊事件:d。奇怪的是,我在第一個地方使用它(在綁定click事件之前)並沒有被解僱。即使在Drupal緩存刷新後。 – Nemeth
謝謝Nemeth –