How to Create switcherConfig option in ui component form

How to Create switcherConfig option in ui component form


Hi Magento friend today's i'm share How to Create switcherConfig option in ui component form 

In Uicomponent create a field - 

How we are Integrate the coustomer Email Country options in uicomponent Form - 

here general is fieldset name 

and customer_email and customer_country is a field name 

uicomponent file name is webpush_customer_form.xml

 

<field name="select_customer" formElement="select">

    <settings>

        <dataType>text</dataType>

        <dataScope>select_customer</dataScope>

        <label translate="true">Select Customer</label>

        <validation>

            <rule name="required-entry" xsi:type="boolean">true</rule>

        </validation>

        <switcherConfig>

            <rules>

                <rule name="0">

                    <value>0</value>

                    <actions>

                        <action name="0">

                            <target>webpush_customer_form.webpush_customer_form.general.customer_email</target>

                            <callback>show</callback>

                        </action>

                        <action name="1">

                            <target>webpush_customer_form.webpush_customer_form.general.customer_country</target>

                            <callback>hide</callback>

                        </action>

                    </actions>

                </rule>

                <rule name="1">

                    <value>1</value>

                    <actions>

                        <action name="0">

                            <target>webpush_customer_form.webpush_customer_form.general.customer_country</target>

                            <callback>show</callback>

                        </action>

                        <action name="1">

                            <target>webpush_customer_form.webpush_customer_form.general.customer_email</target>

                            <callback>hide</callback>

                        </action>

                    </actions>

                </rule>

            </rules>

            <enabled>true</enabled>

        </switcherConfig>

    </settings>

    <formElements>

        <select>

            <settings>

                <options class="Mageget\WebPushNotification\Model\Options\Options" />

            </settings>

        </select>

    </formElements>

</field>


Create a file Options.php in vendor_name\module_name\Model\Options\


<?php

namespace Mageget\WebPushNotification\Model\Options;

use Magento\Framework\Data\OptionSourceInterface;

class Options implements OptionSourceInterface {

    public function getOptionArray() {

        return [0 => __('Customer Email Basis'), 1 => __('Customer Country Basis') ];

    }

    public function toOptionArray() {

        $options[] = ['label' => '', 'value' => ''];

        $availableOptions = $this->getOptionArray();

        foreach ($availableOptions as $key => $value) {

            $options[] = ['label' => $value, 'value' => $key, ];

        }

        return $options;

    }

}


How to Create switcherConfig option in ui component form




How to Create switcherConfig option in ui component form








Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post