Skip to content

[Proposal] Support arrays on default and default_cb for repeatable fields #1286

@rubengc

Description

@rubengc

Actually, if you provide a default or default_cb as array on a repeatable field will result that this field will get initialized with the correct number of fields as array

A text field setup like:

	$cmb_demo->add_field( array(
		'name'         => __( 'Test', 'cmb2' ),
		 'type'          => 'text',
		'repeatable' => true,
		'default'       => array('Text 1','Text 2','Text 3'),
	) );

Actually results on a repeatable text field with 3 inputs (one for each array value) which is an awesome feature to have

On issue #1285 I was described that with this current ability I initiate a colorpicker field with a set of values but there is just one issue

Each field is created with each array value, what is ok, but the empty field (the last that CMB2 uses as pattern to duplicate) receives the full array as value

My proposal, if value given as default or default_cb is an array and field is repeatable, for the empty field pass an empty value instead of the array to avoid issue as described on #1285

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