1

I'm trying to create a Button Field on a UI Component Admin Form but it looks like it's not calling the Controller. It doesn't call the custom controller,But it works when i call the defaults of Magento (save, delete, back, reset), why?.

What could it be?

Button field code

<button name="delete_header">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="buttonClasses" xsi:type="string">custom-button-class</item>
            <item name="actions" xsi:type="array">
                <item name="0" xsi:type="array">
                    <item name="targetName" xsi:type="string">api_data_form.api_data_form_data_source</item>
                    <item name="actionName" xsi:type="string">api/data/deleteheader</item>
                </item>
            </item>
        </item>
    </argument>
    <settings>
        <displayAsLink>false</displayAsLink>
        <title translate="true">Delete Selected Header</title>
    </settings>
</button>
7
  • where u are defining this button?
    – sudo55
    Commented Jun 25, 2020 at 12:19
  • In the form.xml Commented Jun 25, 2020 at 12:20
  • where u have put this form.xml file?
    – sudo55
    Commented Jun 25, 2020 at 12:22
  • view/ adminhtml/ ui_component/ form.xml The form is working good, but this custom button looks like is not calling right the controller. Commented Jun 25, 2020 at 12:26
  • you have defined api/data/deleteheader url, what is your frontname?
    – sudo55
    Commented Jun 25, 2020 at 12:35

2 Answers 2

0

This Works Fine ...Try This Out..

 <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string" translate="true">Add New</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/edit</item>
            </item>
        </item>
4
  • I tried this and shows this exception: Element 'item': This element is not expected. Commented Jun 26, 2020 at 12:21
  • Follow This Link This Works Perfectly Fine...[meetanshi.com/blog/create-admin-grid-magento-2/] Commented Jun 26, 2020 at 12:23
  • And Also...You can declare buttons inside the <argument name="data" xsi:type="array"> Commented Jun 26, 2020 at 12:38
  • Actually i don't know if this will help, because i'm creating a ui component admin form with fieldsets. Commented Jun 26, 2020 at 12:59
0

Try this

<button name="add_address" component="Magento_Customer/js/address/default-address">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="formElement" xsi:type="string">container</item>
            <item name="buttonClasses" xsi:type="string">add-new-address-button</item>
            <item name="actions" xsi:type="array">
                <item name="0" xsi:type="array">
                    <item name="targetName" xsi:type="string">${ $.parentName}.customer_address_update_modal.update_customer_address_form_loader</item>
                    <item name="actionName" xsi:type="string">destroyInserted</item>
                </item>
                <item name="1" xsi:type="array">
                    <item name="targetName" xsi:type="string">${ $.parentName}.customer_address_update_modal</item>
                    <item name="actionName" xsi:type="string">openModal</item>
                </item>
                <item name="2" xsi:type="array">
                    <item name="targetName" xsi:type="string">${ $.parentName}.customer_address_update_modal.update_customer_address_form_loader</item>
                    <item name="actionName" xsi:type="string">render</item>
                </item>
            </item>
        </item>
    </argument>
    <settings>
        <title translate="true">Add New Address</title>
        <imports>
            <link name="parentId">${ $.provider}:data.customer_id</link>
        </imports>
    </settings>
</button>

Reference Path: magentoRoot/vendor/magento/module-customer/view/base/ui_component/customer_form.xml

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.