I am using magento 2.1

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>
share|improve this question
    
what is the issue using above code? – Rakesh 16 hours ago
    
@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. – Deexit Sanghani 16 hours ago

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;
    }
}
share|improve this answer

Use this fieldset :

<item name="formElement" xsi:type="string">radioset</item>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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