Home › Forums › General Issues › Time picker: Keep quarter hours
Hello,
Is it possible to make my timepicker keep only the quarter hours (00, 15, 30 and 45) when selecting the minutes?
Thanks.
You need to alter the arguments to the time piker using javascript https://www.advancedcustomfields.com/resources/javascript-api/#actions-time_picker_init. I don’t know what these arguments are or how to change them. The time picker is the jQuery time picker and documentation can be found here I think https://timepicker.co/
Perfect, this is the information I was missing!
I’ll watch this, thank you!
There is something that I don’t understand.
In my function.php
I added the action:
acf/input/admin_enqueue_scripts
And then in my JS script:
jQuery(document).ready(function($) {
var acfVersion = acf.get('acf_version');
console.log(acfVersion);
acf.addAction('time_picker_init', function( $input, args, field ) {
console.log($input);
console.log(args);
console.log(field);
});
});
Nothing is happening except the version of ACF (which is used just for testing).
Do you know why ?
Like this:
function my_acf_admin_enqueue_scripts() {
wp_enqueue_script( 'acf-datetime', get_stylesheet_directory_uri() . '/js/acf-datetime.js', false, '1.0.0' );
}
add_action('acf/input/admin_enqueue_scripts', 'my_acf_admin_enqueue_scripts');
set $deps
wp_enqueue_script( 'acf-datetime', get_stylesheet_directory_uri() . '/js/acf-datetime.js', array('acf-input'), '1.0.0' );
I don’t have any feedback in my console either:
acf.add_filter('time_picker_args', function( args, field ){
console.log(args);
return args;
});
if this is runnin
var acfVersion = acf.get('acf_version');
console.log(acfVersion);
but the rest in not then I don’t know. I don’t see any reason that it should not be and I’m a little confused by that.
I have 2 time pickers, is this a problem?
Here is my full code, I don’t understand too:
jQuery(document).ready(function($) {
var acfVersion = acf.get('acf_version');
console.log(acfVersion);
/*
acf.addAction('time_picker_init', function( $input, args, field ) {
console.log($input);
console.log(args);
console.log(field);
});
*/
acf.add_filter('time_picker_args', function( args, field ){
console.log(args);
console.log(field);
return args;
});
});
That should not cause anything except for both running. It it was working you would check the field
to see if it is the field you want to alter before changed args
Unless the filter is being applied after the hook is run.
instead of
jQuery(document).ready(function($) {
....
});
try
(function($){
....
})(jQuery);
The problem came from the jQuery(document).ready
!
Many thanks. 🙂
You must be logged in to reply to this topic.
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.