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