• Resolved jaydd

    (@jaydd)


    Hi,
    after clicking into and than out of a text_time field, the time is automatically set.
    This is a problem, because this makes the fields content UNDELETABLE.

    If i select the text_time input fields’ content and delete it(mouse select-backspace delete), then click out of it, the time is again automatically set, so it is not possible to delete the content of the field at all.
    Can this somehow be disabled?
    Thanks,
    Daniel

    • This topic was modified 3 years, 7 months ago by jaydd.
    • This topic was modified 3 years, 7 months ago by jaydd.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Can you provide your CMB2 configuration for your fields here? I’d like to see if I can recreate in a dev install.

    Thread Starter jaydd

    (@jaydd)

    yep, it is in a repeatable group like this:

    add_action('cmb2_admin_init', 'eschstandort_register_repeatable_group_field_metabox');
    /**
     * Hook in and add a metabox to demonstrate repeatable grouped fields
     */
    function eschstandort_register_repeatable_group_field_metabox()
    {
    
    	/**
    	 * Repeatable Field Groups
    	 */
    	$cmb_group = new_cmb2_box(array(
    		'id'           => 'eschstandort_group_metabox',
    		'title'        => esc_html__('Unterrichten des Standorts', 'cmb2'),
    		'object_types' => array('eschstandort'),
    	));
    
    	// $group_field_id is the field id string, so in this case: 'eschstandort_group_demo'
    	$group_field_id = $cmb_group->add_field(array(
    		'id'          => 'eschstandort_group_standort',
    		'type'        => 'group',
    		'description' => esc_html__('Geben Sie hier die Unterrichten dieses Standort ein', 'cmb2'),
    		'options'     => array(
    			'group_title'    => esc_html__('Unterricht {#}', 'cmb2'), // {#} gets replaced by row number
    			'add_button'     => esc_html__('Unterricht hinzufügen', 'cmb2'),
    			'remove_button'  => esc_html__('Unterricht l?schen', 'cmb2'),
    			'sortable'       => true,
    			// 'closed'      => true, // true to have the groups closed by default
    			// 'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ), // Performs confirmation before removing group.
    		),
    	));
    
    	/**
    	 * Group fields works the same, except ids only need
    	 * to be unique to the group. Prefix is not needed.
    	 *
    	 * The parent field's id needs to be passed as the first argument.
    	 */
    	/*
    	  array(
    			'standard' => esc_html__('Option One', 'cmb2'),
    			'custom'   => esc_html__('Option Two', 'cmb2'),
    			'none'     => esc_html__('Option Three', 'cmb2'),
    		)
    	 */
    	$unterrichten = get_posts([
    		'post_type' => 'eschunterricht',
    		'post_status' => 'publish',
    		'numberposts' => -1
    		// 'order'    => 'ASC'
    	]);
    	$unterricht_list = [];
    	foreach ($unterrichten as $unterricht) {
    		//$unterricht->ID
    		$name = get_post_meta($unterricht->ID, 'eschunterricht_name', true);
    		// strip out all whitespace
    		$zname_clean = preg_replace('/\s*/', '', $name);
    		// convert the string to all lowercase
    		$zname_clean = strtolower($zname_clean);
    		$unterricht_list[$unterricht->ID] = esc_html__($name, 'cmb2');
    	}
    	$cmb_group->add_group_field($group_field_id, array(
    		'name'             => esc_html__('Unterricht ausw?hlen', 'cmb2'),
    		'desc'             => esc_html__('Welche Unterricht m?chten Sie zu diesen Standort hinzufügen?', 'cmb2'),
    		'id'               => 'eschstandort_unterricht_select',
    		'type'             => 'select',
    		'show_option_none' => true,
    		'options'          => $unterricht_list,
    	));
    
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => __('Anfangstag', 'cmb2'),
    		'desc' => __('Das Unterricht wird an oder nach diesen Tag Anfangen, je nach welche Tagen Sie unten eingeben. Z.b.: Sie tragen hier Sonntag ein, aber unten Sie stellen ein dass diesen Unterricht nur am Dienstag und Donnerstag stattfindet, dann werden die Unterrichten am ersten Dienstag nach diesen Sonntag anfangen.', 'cmb2'),
    		'id'   => 'eschstandort_unterricht_start_textdate',
    		'type' => 'text_date',
    		'attributes' => array(
    			// CMB2 checks for datepicker override data here:
    			'data-datepicker' => json_encode(array(
    				// dayNames: https://api.jqueryui.com/datepicker/#option-dayNames
    				'dayNames' => array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag	'),
    				// monthNamesShort: https://api.jqueryui.com/datepicker/#option-monthNamesShort
    				'monthNamesShort' => explode(',', 'Jan,Feb,Marz,Apr,Mai,Juni,July,Aug,Sept,Okt,Nov,Dez'),
    				// yearRange: https://api.jqueryui.com/datepicker/#option-yearRange
    				// and https://stackoverflow.com/a/13865256/1883421
    				'yearRange' => '-100:+0',
    				// Get 1990 through 10 years from now.
    				// 'yearRange' => '1990:'. ( date( 'Y' ) + 10 ),
    			)),
    		),
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Montag',
    		'id' => 'esch_montag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Dienstag',
    		'id' => 'esch_dienstag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Mittwoch',
    		'id' => 'esch_mittwoch',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Donnerstag',
    		'id' => 'esch_donnerstag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Freitag',
    		'id' => 'esch_freitag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Samstag',
    		'id' => 'esch_samstag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Sonntag',
    		'id' => 'esch_sonntag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    }
    • This reply was modified 3 years, 7 months ago by jaydd.
    Thread Starter jaydd

    (@jaydd)

    and the composer.lock:

    {
        "_readme": [
            "This file locks the dependencies of your project to a known state",
            "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
            "This file is @generated automatically"
        ],
        "content-hash": "1a0e9a91cfd3a7b09525acd000235489",
        "packages": [
            {
                "name": "cmb2/cmb2",
                "version": "dev-master",
                "source": {
                    "type": "git",
                    "url": "https://github.com/CMB2/CMB2.git",
                    "reference": "cacbc8cedbfdf8ffe0e840858e6860f9333c33f2"
                },
                "dist": {
                    "type": "zip",
                    "url": "https://api.github.com/repos/CMB2/CMB2/zipball/cacbc8cedbfdf8ffe0e840858e6860f9333c33f2",
                    "reference": "cacbc8cedbfdf8ffe0e840858e6860f9333c33f2",
                    "shasum": ""
                },
                "require": {
                    "php": ">5.2.4"
                },
                "require-dev": {
                    "apigen/apigen": "4.1.2",
                    "awesomemotive/am-cli-tools": ">=1.3.1",
                    "nette/utils": "2.5.3",
                    "phpunit/phpunit": "6.5.13"
                },
                "suggest": {
                    "composer/installers": "~1.0"
                },
                "type": "wordpress-plugin",
                "notification-url": "https://packagist.org/downloads/",
                "license": [
                    "GPL-2.0-or-later"
                ],
                "authors": [
                    {
                        "name": "Justin Sternberg",
                        "email": "[email protected]",
                        "homepage": "https://dsgnwrks.pro",
                        "role": "Developer"
                    },
                    {
                        "name": "WebDevStudios",
                        "email": "[email protected]",
                        "homepage": "https://github.com/WebDevStudios",
                        "role": "Developer"
                    }
                ],
                "description": "CMB2 is a metabox, custom fields, and forms library for WordPress that will blow your mind.",
                "homepage": "https://github.com/CMB2/CMB2",
                "keywords": [
                    "metabox",
                    "plugin",
                    "wordpress"
                ],
                "time": "2021-03-04T02:18:53+00:00"
            }
        ],
        "packages-dev": [],
        "aliases": [],
        "minimum-stability": "stable",
        "stability-flags": {
            "cmb2/cmb2": 20
        },
        "prefer-stable": false,
        "prefer-lowest": false,
        "platform": [],
        "platform-dev": [],
        "plugin-api-version": "1.1.0"
    }
    
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I think you accidentally overwrote your first reply with the CMB2 configuration code in it, which is what I would need more than anything from Composer.

    Thread Starter jaydd

    (@jaydd)

    it is held for review it seems, but here it is, hopefully it allows it:

    add_action('cmb2_admin_init', 'eschstandort_register_repeatable_group_field_metabox');
    /**
     * Hook in and add a metabox to demonstrate repeatable grouped fields
     */
    function eschstandort_register_repeatable_group_field_metabox()
    {
    
    	/**
    	 * Repeatable Field Groups
    	 */
    	$cmb_group = new_cmb2_box(array(
    		'id'           => 'eschstandort_group_metabox',
    		'title'        => esc_html__('Unterrichten des Standorts', 'cmb2'),
    		'object_types' => array('eschstandort'),
    	));
    
    	// $group_field_id is the field id string, so in this case: 'eschstandort_group_demo'
    	$group_field_id = $cmb_group->add_field(array(
    		'id'          => 'eschstandort_group_standort',
    		'type'        => 'group',
    		'description' => esc_html__('Geben Sie hier die Unterrichten dieses Standort ein', 'cmb2'),
    		'options'     => array(
    			'group_title'    => esc_html__('Unterricht {#}', 'cmb2'), // {#} gets replaced by row number
    			'add_button'     => esc_html__('Unterricht hinzufügen', 'cmb2'),
    			'remove_button'  => esc_html__('Unterricht l?schen', 'cmb2'),
    			'sortable'       => true,
    			// 'closed'      => true, // true to have the groups closed by default
    			// 'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ), // Performs confirmation before removing group.
    		),
    	));
    
    	/**
    	 * Group fields works the same, except ids only need
    	 * to be unique to the group. Prefix is not needed.
    	 *
    	 * The parent field's id needs to be passed as the first argument.
    	 */
    	/*
    	  array(
    			'standard' => esc_html__('Option One', 'cmb2'),
    			'custom'   => esc_html__('Option Two', 'cmb2'),
    			'none'     => esc_html__('Option Three', 'cmb2'),
    		)
    	 */
    	$unterrichten = get_posts([
    		'post_type' => 'eschunterricht',
    		'post_status' => 'publish',
    		'numberposts' => -1
    		// 'order'    => 'ASC'
    	]);
    	$unterricht_list = [];
    	foreach ($unterrichten as $unterricht) {
    		//$unterricht->ID
    		$name = get_post_meta($unterricht->ID, 'eschunterricht_name', true);
    		// strip out all whitespace
    		$zname_clean = preg_replace('/\s*/', '', $name);
    		// convert the string to all lowercase
    		$zname_clean = strtolower($zname_clean);
    		$unterricht_list[$unterricht->ID] = esc_html__($name, 'cmb2');
    	}
    	$cmb_group->add_group_field($group_field_id, array(
    		'name'             => esc_html__('Unterricht ausw?hlen', 'cmb2'),
    		'desc'             => esc_html__('Welche Unterricht m?chten Sie zu diesen Standort hinzufügen?', 'cmb2'),
    		'id'               => 'eschstandort_unterricht_select',
    		'type'             => 'select',
    		'show_option_none' => true,
    		'options'          => $unterricht_list,
    	));
    
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => __('Anfangstag', 'cmb2'),
    		'desc' => __('Das Unterricht wird an oder nach diesen Tag Anfangen, je nach welche Tagen Sie unten eingeben. Z.b.: Sie tragen hier Sonntag ein, aber unten Sie stellen ein dass diesen Unterricht nur am Dienstag und Donnerstag stattfindet, dann werden die Unterrichten am ersten Dienstag nach diesen Sonntag anfangen.', 'cmb2'),
    		'id'   => 'eschstandort_unterricht_start_textdate',
    		'type' => 'text_date',
    		'attributes' => array(
    			// CMB2 checks for datepicker override data here:
    			'data-datepicker' => json_encode(array(
    				// dayNames: https://api.jqueryui.com/datepicker/#option-dayNames
    				'dayNames' => array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag	'),
    				// monthNamesShort: https://api.jqueryui.com/datepicker/#option-monthNamesShort
    				'monthNamesShort' => explode(',', 'Jan,Feb,Marz,Apr,Mai,Juni,July,Aug,Sept,Okt,Nov,Dez'),
    				// yearRange: https://api.jqueryui.com/datepicker/#option-yearRange
    				// and https://stackoverflow.com/a/13865256/1883421
    				'yearRange' => '-100:+0',
    				// Get 1990 through 10 years from now.
    				// 'yearRange' => '1990:'. ( date( 'Y' ) + 10 ),
    			)),
    		),
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Montag',
    		'id' => 'esch_montag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Dienstag',
    		'id' => 'esch_dienstag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Mittwoch',
    		'id' => 'esch_mittwoch',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Donnerstag',
    		'id' => 'esch_donnerstag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Freitag',
    		'id' => 'esch_freitag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Samstag',
    		'id' => 'esch_samstag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    	$cmb_group->add_group_field($group_field_id, array(
    		'name' => 'Sonntag',
    		'id' => 'esch_sonntag',
    		'type' => 'text_time',
    		'time_format' => 'H:i',
    	));
    }
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I have it copy/pasted now in case it goes for that again. I’ll get back to you as soon as I can with any news.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Definitely seeing what you mean, and I’m not sure at the moment how to handle preventing that in the admin area.

    However, at least when it comes to display, you could do some conditional checks, perhaps something like this:

    
    $time_start = get_post_meta( get_the_ID(), 'esch_donnerstag', true );
    if ( ! empty( $time_start ) && '00:00' !== $time_start ) {
        echo $time_start;
    }
    

    This way it would only output the value if it’s set and not that “00:00” value.

    Thread Starter jaydd

    (@jaydd)

    hm,oke thanks! good to know that it′s not only for me. I ll see what i can do then with some js i guess. The problem with the temporary solution above is that it′s not only being set to 00:00, but to whatever is already set in the field

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    when in doubt, if needing to “null” it out, that could be a viable fallback value that gets typed in.

    Thread Starter jaydd

    (@jaydd)

    I see in cmb2.js line929 that this behavior seems to be intended.
    But anyways, here is a jquery workaround for anyone having the same problem:

      jQuery(".cmb2-timepicker").blur(function() {
        console.log('out');
        if(jQuery(this)[0].innerHTML.trim().length === 0){
          jQuery(this).val('');
        }
    });
    • This reply was modified 3 years, 7 months ago by jaydd.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds good.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘text_time field content not deletable after clicking into’ is closed to new replies.