Skip to content

Form ui fieldset load data

I used the Magento 2 plugin in PhpStorm to create an entity with grid and form. It seems to work great until I renamed the fieldset name to “foo” and added tabs.

I already looked up many related posts/questions and did some digging in de vendor folder. But I can’t seem to find it, the data simply won’t fill the input fields unless the fieldset name is general. here is a code snippet of my form: app/code/Vendor/SalesPromotion/view/adminhtml/ui_component/sales_promotion_form.xml

<?xml version="1.0"?>
<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">sales_promotion_form.sales_promotion_form_data_source</item>
            <item name="deps" xsi:type="string">sales_promotion_form.sales_promotion_form_data_source</item>
        </item>
        <item name="config" xsi:type="array">
            <item name="dataScope" xsi:type="string">data</item>
            <item name="namespace" xsi:type="string">sales_promotion_form_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Sales Promotion Form</item>
    </argument>
    <settings>
        <layout>
            <navContainerName>left</navContainerName>
            <type>tabs</type>
        </layout>
        <buttons>
            <button name="save" class="VendorSalesPromotionBlockFormSalesPromotionSave"/>
            <button name="back" class="VendorSalesPromotionBlockFormSalesPromotionBack"/>
            <button name="delete" class="VendorSalesPromotionBlockFormSalesPromotionDelete"/>
        </buttons>
    </settings>
    <dataSource name="sales_promotion_form_data_source" component="Magento_Ui/js/form/provider">
        <settings>
            <submitUrl path="sales_promotion/salespromotion/save"/>
        </settings>
        <dataProvider class="VendorSalesPromotionUiDataProviderSalesPromotionDataProvider" name="sales_promotion_form_data_source">
            <settings>
                <requestFieldName>sales_promotion_id</requestFieldName>
                <primaryFieldName>sales_promotion_id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <fieldset name="foo" sortOrder="10">
        <settings>
            <label translate="true">General</label>
            <dataScope/>
        </settings>
        <field name="sales_promotion_id" sortOrder="0" formElement="hidden">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">sales_promotion_id</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <label translate="true">Entity ID</label>
                <dataScope>sales_promotion_id</dataScope>
            </settings>
        </field>
        <field name="name" sortOrder="00" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">name</item>
                </item>
            </argument>
            <settings>
                <dataType>string</dataType>
                <label translate="true">Name</label>
                <dataScope>name</dataScope>
            </settings>
        </field>
    </fieldset>
    <fieldset name="bar" sortOrder="20">
        <settings>
            <label translate="true">Conditions</label>
            <dataScope/>
        </settings>
        <field name="min_cart_total" sortOrder="80" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">min_cart_total</item>
                </item>
            </argument>
            <settings>
                <dataType>float</dataType>
                <label translate="true">Min Cart Total</label>
                <dataScope>min_cart_total</dataScope>
            </settings>
        </field>
    </fieldset>
    <fieldset name="howdy" sortOrder="30">
        <settings>
            <label translate="true">Email</label>
            <dataScope/>
        </settings>
        <field name="email_template" sortOrder="110" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">email_template</item>
                </item>
            </argument>
            <settings>
                <dataType>string</dataType>
                <label translate="true">Email Template</label>
                <dataScope>email_template</dataScope>
            </settings>
        </field>
    </fieldset>
</form>