7

I need to create gender radio input using magento ui component form

<field name="gender">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="description" xsi:type="string" translate="true">Gender</item>
                    <item name="dataType" xsi:type="string">boolean</item>
                    <item name="formElement" xsi:type="string">radio</item>
                    <item name="valueMap" xsi:type="array">
                        <item name="true" xsi:type="boolean">male</item>
                        <item name="false" xsi:type="boolean">femal</item>
                    </item>
                </item>
            </argument>
    </field>
2
  • what is the issue using above code? Jan 10, 2017 at 10:22
  • @Rakesh it's given error Exception #0 (Magento\Framework\Exception\LocalizedException): The requested component ("radio") is not found. Before using, you must add the implementation. Jan 10, 2017 at 10:28

2 Answers 2

10

Finally i got the answer

<field name="gender">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">[vendor]\[module]\Model\Config\Source\Gender</item>
            <item name="config" xsi:type="array">                    
                <item name="sortOrder" xsi:type="number">20</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">radioset</item>
                <item name="label" xsi:type="string" translate="true">Gender</item>
                <item name="source" xsi:type="string">category</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
            </item>
        </argument>
    </field>

Create > [vendor]/[module]/Model/Config/Source/Gender.php

namespace [Vendor]\[module]\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Gender implements ArrayInterface
{
    /**
     * @return array
     */
    public function toOptionArray()
    {
        $options = [
            0 => [
                'label' => 'Male',
                'value' => 'male'
            ],
            1 => [
                'label' => 'Female',
                'value' => 'female'
            ],
        ];

        return $options;
    }
}
2

Use this fieldset :

<item name="formElement" xsi:type="string">radioset</item>

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.