Hello,
I have read a lot and tried several attempts to achieve something easy but I am unable to do that.
I would like to set maxDate and minDate to the Date Picker field..
I would also like to set 5 minutes intervals to 2 Time Picker fields but it doesnt work.
I am confused, can someone please helpe me out?
The thing is I dont know how to get the element ID of the date picker and also the time picker fields.
Please help me out.
This is what I have written in my functions file:
/*
@ Format Date time picker fields
*/
function my_acf_input_admin_footer() {
?>
<script type="text/javascript">
(function($) {
// JS here
acf.add_filter('date_picker_args', function( args, $field ){
// do something to args
var datepicker_id = $('.acf-date-picker input[type=\"hidden\"]').attr('id');
alert(datepicker_id);
$('.acf-date-picker input.hasDatepicker').datepicker( "option", "maxDate", "+1m +1w" );
// return
return args;
});
acf.add_filter('time_picker_args', function( args, $field ){
// do something to args
$('.acf-time-picker').timepicker({
stepMinute: 5
});
// return
return args;
});
})(jQuery);
</script>
<?php
}
add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
Ok..solved it..
Perhaps, you should add an example, it was realy confusing for me.
This is the solution:
/*
@ Format Date time picker fields
*/
function my_acf_input_admin_footer() {
?>
<script type="text/javascript">
(function($) {
// JS here
acf.add_filter('date_picker_args', function( args, $field ){
// do something to args
args['minDate'] = "-30"; //For example, "+1m +7d" represents one month and seven days from today.
args['maxDate'] = "30";
return args;
});
acf.add_filter('time_picker_args', function( args, $field ){
// do something to args
args['stepMinute'] = 5;
// return
return args;
});
})(jQuery);
</script>
<?php
}
add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
I know it’s an old post, but I just wanted to thank you for publishing your solution. Just saved me a lot of time!