Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Multi Picker inside Addable Box, how to reference?

Open robioat opened this issue 10 years ago • 4 comments

Hi guys :)

Similar to this issue (https://github.com/ThemeFuse/Unyson/issues/1446), but it's with the preset value part (and getting them to be pre populated with a multi picker inside an addable box, so multiple added boxes already there with a preselected multi picker in there). The template works in the following code, but the preset values doesn't. {{- opt_single_title_rows.the_block_type }} isn't working in the value part.

'opt_single_title_functionality'=> array(
	'type' =>'addable-box',
	'label' => __('Add Title Elements', 'thshpr'),
	'template' => '{{- opt_single_title_rows.the_block_type }}', // this does work
	'help' => __( 'Add and order (drag and drop) the title elements to be displayed for this post.', 'thshpr'  ),
	'size' =>'small', 
	'limit' => 0, 
	'value' => array(
		array(
			'{{- opt_single_title_rows.the_block_type }}' => 'Title', // this doesn't work
		),
		array(
			'{{- opt_single_title_rows.the_block_type }}' => 'Spacer 10px',
		),
	),
	'box-options' => array(
		'opt_single_title_rows' =>array(
			'type'  => 'multi-picker',
			'picker' => array(
				'the_block_type' => array(
					'type'    => 'select',
					'choices' => array(
						'Title' => __('Title', 'thshpr'),
						'Spacer 10px' => __('Spacer 10px', 'thshpr'),
						'Spacer 5px' => __('Spacer 5px', 'thshpr'),
						'Spacer 2px' => __('Spacer 2px', 'thshpr'),
						'Spacer 1px' => __('Spacer 1px', 'thshpr'),
					),
				),
			),
			'choices' => array(
				'Title' => array(
					'label' => __( 'Title', 'thshpr' ),
				),
				'Spacer 10px' => array(
					'label' => __( 'Spacer 10px', 'thshpr' ),
				),
				'Spacer 5px' => array(
					'label' => __( 'Spacer 5px', 'thshpr' ),
				),
				'Spacer 2px' => array(
					'label' => __( 'Spacer 2px', 'thshpr' ),
				),
				'Spacer 1px' => array(
					'label' => __( 'Spacer 1px', 'thshpr' ),
				),
			),
			'show_borders' => false,
		),
	),
),

Cleaned up and trimmed the code, Hope this now makes sense, thanks :)

robioat avatar Nov 25 '16 20:11 robioat

The template works in the following code, but the preset values doesn't. {{- opt_single_title_rows.the_block_type }} isn't working in the value part.

The 'template' parameter is used in javascript ( 1 -> 2 ). It is not something magical. So you can't use {{- ... }} everywhere you want and expect it to work (to be replaced with value)

ghost avatar Nov 28 '16 11:11 ghost

Hi, Ok understood, so how would I fill in the value for this?

Is there no way to set up defaults when using a multi picker inside an addable box? Obviously, as per the code I would like the inner options of the multi picker to be the ones visible in the value selection.

So, for example, there might be two addable boxes initially set up, the first one has say, "title" and the second "spacer". I can get this to work with a normal select, but there are sub options on some of the selects, so it has to be a multi picker.

For example:

'value' => array(
			array(
				'opt_header_featuredposts_rows' => 'Thumbnail',
			),
			array(
				'opt_header_featuredposts_rows' => 'Title',
			),
			array(
				'opt_header_featuredposts_rows' => 'Excerpt',
			),
			array(
				'opt_header_featuredposts_rows' => 'Date+Comments',
			),
			array(
				'opt_header_featuredposts_rows' => 'Categories',
			),
		),
		'desc' => __('Add / remove / reorder elements to be displayed in each post', 'thshpr'),
		'template' => '{{- opt_header_featuredposts_rows }}',
		'popup-title' => null,
		'size' =>'small', 
		'limit' => 0, 
		'box-options' => array(
			'opt_header_featuredposts_rows' => array(

Works with a normal select, but how do I target the equivalent of "opt_header_featuredposts_rows" in the above example with a multi picker?

robioat avatar Nov 28 '16 19:11 robioat

How about something like this?

value => array(
    array(
        'opt_single_title_rows' => array(
            'the_block_type' => 'Title', // choice
            'Title' => 'somevalue' // choice 1 data
            'Excerpt' => 'othervalue' // choice 2 data
            //...
        ),
    ),
),

albertso avatar Dec 19 '16 01:12 albertso

$options = array(
	'opt_single_title_functionality'=> array(
		'type' => 'addable-box',
		'label' => __('Add Title Elements', 'thshpr'),
		'template' => '{{- opt_single_title_rows.the_block_type }}', // this does work
		'help' => __( 'Add and order (drag and drop) the title elements to be displayed for this post.', 'thshpr'  ),
		'size' =>'small',
		'limit' => 0,
		'value' => array(
			array(
				'opt_single_title_rows' => array(
					'the_block_type' => 'Title',
				),
			),
			array(
				'opt_single_title_rows' => array(
					'the_block_type' => 'Spacer 10px',
				),
			),
		),
		'box-options' => array(
			'opt_single_title_rows' =>array(
				'type'  => 'multi-picker',
				'picker' => array(
					'the_block_type' => array(
						'type'    => 'select',
						'choices' => array(
							'Title' => __('Title', 'thshpr'),
							'Spacer 10px' => __('Spacer 10px', 'thshpr'),
							'Spacer 5px' => __('Spacer 5px', 'thshpr'),
							'Spacer 2px' => __('Spacer 2px', 'thshpr'),
							'Spacer 1px' => __('Spacer 1px', 'thshpr'),
						),
					),
				),
				'choices' => array(
					'Title' => array(
						'hello' => array(
							'type' => 'text',
							'label' => __( 'Title', 'thshpr' ),
						),
					),
					'Spacer 10px' => array(
						'hello' => array(
							'type' => 'text',
							'label' => __( 'Spacer 10px', 'thshpr' ),
						),
					),
					'Spacer 5px' => array(
						'hello' => array(
							'type' => 'text',
							'label' => __( 'Spacer 5px', 'thshpr' ),
						),
					),
					'Spacer 2px' => array(
						'hello' => array(
							'type' => 'text',
							'label' => __( 'Spacer 2px', 'thshpr' ),
						),
					),
					'Spacer 1px' => array(
						'hello' => array(
							'type' => 'text',
							'label' => __( 'Spacer 1px', 'thshpr' ),
						),
					),
				),
				'show_borders' => false,
			),
		),
	),
);

ghost avatar Dec 21 '16 13:12 ghost