I have a UI form which contains 2 fields one is 'name' and the other is the 'conditions'. I have tried the below code to display the conditions section and it is working fine. But I did not get the selected conditions in my save controller on form submit. I got the name and form key fields.
Here is my form
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">example_form.example_form_data_source</item>
<item name="deps" xsi:type="string">example_form.example_form_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Label Information</item>
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">data</item>
<item name="namespace" xsi:type="string">example_form</item>
</item>
<item name="template" xsi:type="string">templates/form/collapsible</item>
<item name="buttons" xsi:type="array">
<item name="save" xsi:type="string">Vendor\Example\Block\Adminhtml\Productlabel\Edit\Button\Save</item>
<item name="back" xsi:type="string">Vendor\Example\Block\Adminhtml\Productlabel\Edit\Button\Back</item>
</item>
</argument>
<dataSource name="example_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Vendor\Example\Model\ResourceModel\Productlabel\DataProvider</argument>
<argument name="name" xsi:type="string">example_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">label_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="submit_url" xsi:type="url" path="example/example/save"/>
</item>
</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</dataSource>
<fieldset name="example_details">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="collapsible" xsi:type="boolean">false</item>
<item name="label" xsi:type="string" translate="true">Basic Details</item>
<item name="openOnShow" xsi:type="boolean">true</item>
</item>
</argument>
<field name="name">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Name</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">name</item>
<item name="dataScope" xsi:type="string">name</item>
</item>
</argument>
</field>
</fieldset>
<fieldset name="conditions_serialized">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Conditions</item>
<item name="collapsible" xsi:type="boolean">true</item>
</item>
</argument>
<container name="conditions_serialized_container" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Conditions</argument>
</htmlContent>
</container>
</fieldset>
</form>
Output: https://prnt.sc/nop86z
Controller Function
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$data = $this->getRequest()->getPostValue();
echo '<pre>';print_r($data);exit;
}
Output:https://prnt.sc/nop7oe
I am using magento 2.3 version. Please help me to resolve this
Best Answer
You need to make your custom Conditions.php and just replace $formName argument of addTabToForm function with your form name.
you are using Magento core file and it's adding the selected value of conditions section in sales_rule_form form
Updated code :
eg.
Conditions.php