0

I need to have a multi-select UI Component which is required, but does not select the first option be default? I have this set up but the first time is always selected by default. How can I do this?

$fieldsetSetup->addField('delivery_method', 'multiselect', 
            ['name' => 'delivery_method', 'label' => __('Delivery Method'), 'title' => __('Delivery Method'), 'required' => 'true',
            'values' => array(
                array("value" => "", "label" => "Select"),
                array("value" => "option_1", "label" => "Option 1"),
                array("value" => "option_2", "label" => "Option 2"))
            ]);

Screenshot of the first item in the multiselect selected by default, not what I want

1

You need to pass 'value' => [], to addField(), Replace your code with this

$fieldsetSetup->addField(
    'delivery_method', 
    'multiselect', 
    [
        'name' => 'delivery_method', 
        'label' => __('Delivery Method'), 
        'title' => __('Delivery Method'), 
        'required' => 'true',
        'value' => [],
        'values' => array(
            array("value" => "option_0", "label" => "Select"),
            array("value" => "option_1", "label" => "Option 1"),
            array("value" => "option_2", "label" => "Option 2")
        )
    ]
);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.