0

Thanks in advance, Want to implement jquery date time picker with zend framework 2 using ZF FORM, with validation of form date selection depending on to date.

Please suggest the best practice.

2 Answers2

1

You can proceed as follows

In your form you add a date field:

$this->add([
    'name' => 'birthDate',
    'type' => 'Zend\Form\Element\Date',
    'attributes' => [
        'id' => 'birthDate',
        'class' => 'required datepicker-date',
        'type' => 'text'
    ],
    'options' => [
        'label' => 'Birth date'
    ]
]);

notice the 'type' => 'text'.

Then in the view you print the form element as you please and add the following javascript snippet:

$(document).ready(function() {
    $( ".datepicker-date" ).datepicker({
        dateFormat: "dd-mm-yy",
        changeMonth: true,
        changeYear: true
    });
});

Adjust the options according to your needs.

marcosh
  • 8,780
  • 5
  • 44
  • 74
0

You can do it by using bootstrap-datepicker

So firstly you want to insert following CSS and JS files.Those are

1.bootstrap.css
2.bootstrap-datetimepicker.min.css
3.jquery.min.js
4.bootstrap-datepicker.min.js

<script type="text/javascript">
    $(document).ready(function() {
        $('#yourTextFieldIDName').datepicker({
            format: "yyyy-mm-dd",
            viewMode: "day",
            minViewMode: 'day'
        });
</script>
UWU_SANDUN
  • 1,123
  • 13
  • 19