4

I have a select field in the UI component, on the changing the select field with ajax how to load the next select field.in the admin side?

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Jan 5, 2018 at 12:25

1 Answer 1

2

Please follow below steps.

Step-1: create select box element like below code in your ui_component form xml

 <field name="select_box_1">
 <argument name="data" xsi:type="array">
 <item name="options" xsi:type="object">Namespace\Module\Model\Config\Source\SelectBoxOption</item>
 <item name="config" xsi:type="array">
 <item name="dataType" xsi:type="string">text</item>
 <item name="label" xsi:type="string" translate="true">Select Option</item>
 <item name="component" xsi:type="string">Namespace_Module/js/form/element/select-option</item>
 <item name="formElement" xsi:type="string">select</item>
 <item name="source" xsi:type="string">modulename</item>
 <item name="dataScope" xsi:type="string">select_box_1</item>
 <item name="validation" xsi:type="array">
 <item name="required-entry" xsi:type="boolean">true</item>
 </item>
 </item>
 </argument>
 </field>
<field name="select_box_2">
 <argument name="data" xsi:type="array">
 <item name="options" xsi:type="object">Namespace\Module\Model\Config\Source\SelectBoxTwoOption</item>
 <item name="config" xsi:type="array">
 <item name="dataType" xsi:type="string">text</item>
 <item name="label" xsi:type="string" translate="true">Select Option</item>
 <item name="formElement" xsi:type="string">select</item>
 <item name="source" xsi:type="string">modulename</item>
 <item name="dataScope" xsi:type="string">select_box_2</item>
 <item name="validation" xsi:type="array">
 <item name="required-entry" xsi:type="boolean">true</item>
 </item>
 </item>
 </argument>
 </field>

Step-2: create select-option.js in Namespace/Module/view/adminhtml/web/js/form/element and paste below code in file:

define([
 'jquery',
 'underscore',
 'uiRegistry',
 'Magento_Ui/js/form/element/select',
 'Magento_Ui/js/modal/modal',
], function (,ドル _, uiRegistry, select, modal) {
 'use strict';
 return select.extend({
 /**
 * On value change handler.
 *
 * @param {String} value
 */
 onUpdate: function (value)
 {
 if (value != 'undefined')
 {
 //Do your Ajx stuff here
 }
 return this._super();
 },
 });
});
answered Jan 25, 2018 at 7:08
3
  • Have you idea about how to get value on page load? Commented Oct 9, 2018 at 5:10
  • That you get from Dataprovider class Commented Oct 9, 2018 at 9:14
  • Can you please give me hint in comment? How to use Dataprovider? Commented Oct 9, 2018 at 9:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.