• Resolved TStone

    (@tstone)


    This plugin seems awesome in many ways! ??
    But I find it quite difficult to navigate the documentation. Some things are impossible to find any information on.

    For example, the time picker field can only be used in intervals of 5 minutes, and despite spending a few hours trying to find out how to change it, I still haven’t got a clue.

    I’ve made a custom post type to document theatrical performance pieces, and need to have a field where the time length of each performance piece is entered.
    Some pieces are only 3 minutes, but when trying to enter “3” it is immediately changed to Zero. Entering “5” (or 10, 15, 20, 25…) is possible, but entering the wrong time lengths sort of defeats the whole thing.

    This is what I’m trying to use:

    $cmb_time->add_field( array(
    ‘name’ => esc_html__( ‘Minutes’, ‘ticketbox’ ),
    ‘desc’ => esc_html__( ‘Length in minutes’, ‘ticketbox’ ),
    ‘id’ => $prefix . ‘minutes’,
    ‘type’ => ‘text_time’,
    ‘time_format’ => ‘i’, // Set to minutes format
    ) );

    Is there a better way to solve it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter TStone

    (@tstone)

    Changed it to a standard textfield instead.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    As I recall, the default minute increment is 5 which explains the behavior you were seeing with that, however, we have a filter in place that would allow you to change that.

    It’s found in the CMB2_JS.php file and the localize method around line 179 for version 2.5.1.

    Something like the following should change that value to 1, but I haven’t formally tested it. Just eyeballing the code.

    function tstone_minute_incrementer( $l10n ) {
    	$l10n['defaults']['time_picker']['stepMinute'] = 1;
    
    	return $l10n;
    }
    add_filter( 'cmb2_localized_data', 'tstone_minute_incrementer' );
    
    Plugin Author Justin Sternberg

    (@jtsternberg)

    The filter is there as a last resort. If you filter that, you’ll override all the settings for all fields (even ones part of other 3rd party plugins or themes), so it’s best to use the field-config attributes parameter to override. I have updated the text_time field documentation to demonstrate how this can be done: https://github.com/CMB2/CMB2/wiki/Field-Types#text_time

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What Justin said. I kind of had a hunch that that was maybe possible, but went with the way I was more confident about. ??

    Thread Starter TStone

    (@tstone)

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Time picker problem’ is closed to new replies.