0

我有两个链接的 Bootstrap 日期时间选择器,我使用 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 > #datetimepicker7 和 #datetimepicker6 < #datetimepicker7 )。

这是 ReservationsController 的函数添加:

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']);
}
4

1 回答 1

0

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

于 2016-01-19T00:49:58.867 回答