1

I add dropdown field in admin form to showing status enable or disable like this :

<field name="status">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="label" translate="true" xsi:type="string">Status</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="options" xsi:type="string">Lime\Confirmation\Model\Status</item>
                    <item name="source" xsi:type="string">bank_destination</item>
                    <item name="sortOrder" xsi:type="number">130</item>
                    <item name="dataScope" xsi:type="string">status</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">false</item>
                    </item>
                </item>
            </argument>
        </field>

It calls Model/Status for options label and value. When I load page dropdown not showing any label and value as option. Here's the Model/Status.php:

namespace Lime\Confirmation\Model;

class Status implements \Magento\Framework\Option\ArrayInterface
{
    /**
     * Retrieve options array.
     *
     * @return array
     */
    public function toOptionArray()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    /**
     * Retrieve option array
     *
     * @return string[]
     */
    public static function getOptionArray()
    {
      return [
          '1' => 'Active',
          '0' => 'Inactive',
      ];
    }

    /**
     * Retrieve option array with empty value
     *
     * @return string[]
     */
    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    /**
     * Retrieve option text by option value
     *
     * @param string $optionId
     * @return string
     */
    public function getOptionText($optionId)
    {
        $options = self::getOptionArray();

        return isset($options[$optionId]) ? $options[$optionId] : null;
    }
}
2

Try following way:

<field name="status">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Lime\Confirmation\Model\Status</item>
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">Status</item>
            <item name="dataType" xsi:type="string">number</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="dataScope" xsi:type="string">status</item>
            <item name="sortOrder" xsi:type="number">130</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">false</item>
            </item>
        </item>
    </argument>
</field>

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.