Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Popup Inside Multi Not Returning Array

Open NwpDeveloper opened this issue 10 years ago • 3 comments

I have the following option. [multi][popup]. When I pace the option in pagebuilder I get an empty string for the value of the popup. See Example 1. The array values don't get added until I hit save in the popup even though defaults are set. So, $foo = [ foo][option-1][bar] will cause an illegal string offset unless I save the popup.

Example 1)

[foo]
(
    [option-1] => 'value 1'
    [option-2] => ''
)

Example2)

[foo]
(
    [option_1] => ''
    [option_2] => array
    (
        [bar] => '0'
    )
)

NwpDeveloper avatar Jan 29 '16 23:01 NwpDeveloper

Looks like the documentation is wrong on multi because if you set value array:

array(
    'type'  => 'multi',
    'value' => array(
        'option-1' => 'value 1',
        'option-2' => 'value 2',
    ),


then the if:

if (
  is_array($input_value) ||
  empty($option['value'])
)

doesn't fire the foreach to get values for any sub options. Instead it just returns $value = $option['value']. If option-2 is a popup which an empty string value this flags an exception.

Is the $input_value arg from the html input of the option?

NwpDeveloper avatar Jan 29 '16 23:01 NwpDeveloper

I'm going to close this issue and just note that the documentation is incomplete.

Basically if you are nesting and multi or popup inside another multi or popup do NOT set 'value' for the multi or popup. That way the class will generate default values with empty array and the if will fire the foreach and call the render for any nested options.

NwpDeveloper avatar Jan 30 '16 19:01 NwpDeveloper

Thank you.

You can improve any time you want the documentation by submitting pull requests https://github.com/ThemeFuse/Unyson-Documentation It is not hard, you can do all the work directly on site (fork, edit, pull request) without working with git commands on your pc

ghost avatar Jan 30 '16 20:01 ghost