1
  • I have created a UI select field using PHP, with the below code of lines.

    $data = [
         'arguments' => [
             'data' => [
                 'config' => [
                     'label' => __('Options'),
                     'componentType' => Field::NAME,
                     'formElement' => Select::NAME,
                     'component' => 'Magento_Ui/js/form/element/ui-select',
                     'elementTmpl' => 'ui/grid/filters/elements/ui-select',
                     'selectType' => 'simple',
                     'selectType' => $this->getOptions(),
                     'dataType' => Text::NAME,
                     'sortOrder' => 10,
                     'disableLabel' => true,
                     'multiple' => false,
                     'selectedPlaceholders' => [
                         'defaultPlaceholder' => __('None'),
                     ],
                     'validation' => [
                         'required-entry' => false
                     ],
                     'source' => 'vendorfield',
                     'visible' => 1,
                     'required' => 0,
                     'filterOptions' => true
                 ],
             ],
         ],
     ];
    
  • When the user selects one of the options from the Dropdown then that option will be selected.

  • Now if the user wants to unselect that option. I mean users don`t want to select any value from that dropdown. then what?

  • Currently, the user can`t unselect the selected value.😬

enter image description here

Thanks in advance :)

2 Answers 2

0

Add another option value with empty data that will be treated as no select or add option with "Select from dropdown" that will be treated as no value selected

0

Probably there is no option to unselect a dropdown.

You can add an initial empty value in that dropdown like "Please select a value" so that the admin can easily choose that value whenever they want to unselect the dropdown.

The dropdown option should be ["label" => "Please select a value", "value" => ""]

This option should be placed as the first option in that option dropdown. You can done this inside the "$this->getOptions()" function.

1
  • Thanks for your time. I have already tried this way but the Option is not listed in the Dropdown. Here is an Options array: i.imgur.com/C2aQBnJ.png Commented Jan 24, 2022 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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