Skip to content

Repeatable Field - 2nd row select fields don't use default #1137

Description

@JiveDig

Expected Behavior:

Adding a new row in a repeater uses the default setting for select fields, as defined by the field itself.

Actual Behavior:

2nd row select fields use the first item in the options array instead of the default.

Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):

  1. Create a group field with a select as a group field.
  2. Set a default for the select that is NOT the first item in the options.
  3. Create more than 1 row and the 2nd and on rows will not use the default for the select.

CMB2 Field Registration Code:

add_action('cmb2_init', function() {

	$cmb = new_cmb2_box([
		'id'           => 'test',
		'title'        => 'Test',
		'object_types' => ['post'],
		'context'      => 'normal',
		'priority'     => 'default'
	]);

	$group_field_id = $cmb -> add_field([
		'id'   => 'group',
		'type' => 'group'

	]);

	$cmb->add_group_field( $group_field_id, array(
		'name'    => __( 'Select Field', 'textdomain' ),
		'id'      => 'height',
		'type'    => 'select',
		'default' => 'md',
		'options' => array(
			'auto' => __( 'Auto', 'textdomain' ),
			'xs'   => __( 'Extra Small', 'textdomain' ),
			'sm'   => __( 'Small', 'textdomain' ),
			'md'   => __( 'Medium (Should Be Default)', 'textdomain' ),
			'lg'   => __( 'Large', 'textdomain' ),
			'xl'   => __( 'Extra Large', 'textdomain' ),
		),
	) );

}, 20, 2 );

This was originally brought up in #853 (comment) but later realized this was a different issue. Sorry!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo