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!
The topic ‘Adding custom javascript to date and time picker fields’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.