0

I have two linked Bootstrap datetimepickers that i use wih CakePHP 3.x Here's the code:

<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>

Before clicking on submit button, everything works fine. But after the form is submitted, and validation errors displayed on inputs,the linked pickers no longer works, means i can choose any datetime i want in both pickers without restrictions (like i can choose #datetimepicker6 > #datetimepicker7 and #datetimepicker6 < #datetimepicker7).

Here is the function add of 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']);
}
Br.sasa
  • 49
  • 1
  • 8

1 Answers1

0

Problem solved,the issue was not from the code but from the cookies, i deleted the cookies, and everything worked fine.

Br.sasa
  • 49
  • 1
  • 8