cancel
Showing results for 
Search instead for 
Did you mean: 

Multi select list of attribute to checkbox

Multi select list of attribute to checkbox

Hi,

I need to change the multi select attribute into checkbox so admin can easily checked attribute i am using magento 2.3

4 REPLIES 4

Re: Multi select list of attribute to checkbox

* You can use
<item name="formElement" xsi:type="string">checkboxset</item>
  
Multiselect/checkboxset both return the field value in text format, you need to make changes only to the presentation layer for the attribute. There is a formElement checkbox set in magento which will fulfill your requirement. check the code below
 
<field name="cuisines">
    <argument name="data" xsi:type="array">
        <item name="label" xsi:type="string" translate="true">Cuisines</item>
        <item name="options" xsi:type="object">Ricky\Hoteladvnce\Model\Config\Checkboxcuisines</item>
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">cuisines</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">text</item>
            <item name="formElement" xsi:type="string">checkboxset</item>
            <item name="source" xsi:type="string">module</item>
            <item name="multiple" xsi:type="boolean">true</item>
            <item name="dataScope" xsi:type="string">cuisines</item>
        </item>
    </argument>
</field>
You need to proivde checkbox array to display options in
Ricky\Hoteladvnce\Model\Config\Checkboxcuisines.php
 
public function toOptionArray()
    {
        return [['value' => "mx", 'label' => __('Mexican')], 
                ['value' => "it", 'label' => __('Italian')], 
                ['value' => "in", 'label' => __('Indian')]
               ];
    }
 
Outpurt
test.png
 
 
Find helpful ?Consider Giving Kudos to this post.
Problem solved? ClickAccept as Solution!

Re: Multi select list of attribute to checkbox

hi @Kapil_Thakur 

 

Thank for reply .... but  my question about product page where the attribute (product attribute) with multi select option i need to convert that multi-select in checkbox so user can easily check more then one attribute without ctrl+click to select attribute ..

Re: Multi select list of attribute to checkbox

@piyush_khandelw if your have done this can you provide a solution here

Re: Multi select list of attribute to checkbox

<field name="size">
    <argument name="data" xsi:type="array">
        <item name="label" xsi:type="string" translate="true">Cuisines</item>
        <item name="options" xsi:type="object">Vendor\Model_name\Model\Config\Checkboxzise</item>
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">cuisines</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">text</item>
            <item name="formElement" xsi:type="string">checkboxset</item>
            <item name="source" xsi:type="string">module</item>
            <item name="multiple" xsi:type="boolean">true</item>
            <item name="dataScope" xsi:type="string">size</item>
        </item>
    </argument>
</field>
Vendor\<Module_name>\Model\Config\Checkboxsize


In this class to return array which you want to show in checkbox option
for Example 

return [['value' => "xs", 'label' => __('XS')], 
                ['value' => "s", 'label' => __('S')], 
                ['value' => "m", 'label' => __('M')]
               ];