验证表单后,链接的Bootstrap datetimepicker无法正常工作

时间:2016-01-18 05:31:15

标签: bootstrap-datetimepicker cakephp-3.x eonasdan-datetimepicker

我有两个链接的Bootstrap datetimepickers,我使用CakePHP 3.x这是代码:

<script type="text/javascript">
$(function () {
    $('#datetimepicker6').datetimepicker();
    $('#datetimepicker7').datetimepicker({
        useCurrent: false //Important! See issue #1075
    });
    $("#datetimepicker6").on("dp.change", function (e) {
        $('#datetimepicker7').data("DateTimePicker").minDate(e.date);
    });
    $("#datetimepicker7").on("dp.change", function (e) {
        $('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
    });
});
</script>

在点击提交按钮之前,一切正常。 但是在提交表单并在输入上显示验证错误之后,链接的选择器不再有效,这意味着我可以在两个选择器中选择我想要的任何日期时间而没有限制(例如我可以选择#datetimepicker6&gt; #datetimepicker7和#datetimepicker6&lt; #datetimepicker7)。

这是ReservationsController的函数add:

public function add(){
$reservation = $this->Reservations->newEntity();
if ($this->request->is('post')) {         
$reservation = $this->Reservations->patchEntity($reservation,$this->request-  >data);                                   
        if($reservation->errors()){
            $reservation->errors();
        }else {
        $reservation->startdate = new Time($this->request->data['startdate']) ;
        $reservation->enddate   = new Time($this->request->data['enddate']) ;
        if ($this->Reservations->save($reservation)) {
            $this->Flash->success('The reservation has been saved.');
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error('The reservation could not be saved. Please, try again.');
        }
    }
}       
    $this->set('_serialize', ['reservation']);
}

1 个答案:

答案 0 :(得分:0)

问题解决了,问题不是来自代码,而是来自cookie,我删除了cookie,一切正常。