2

I want to add a UI component form in the admin panel. It is just sending email, no need of database storage. I want to redirect to my form when I click my menu "Send Coupon". I have tried the below UI component XML. But it shows "Not registered handle coupon_email_data_source" error

<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">coupon_email.coupon_email_data_source</item>
            <item name="deps" xsi:type="string">coupon_email.coupon_email_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true"> Information</item>
        <item name="config" xsi:type="array">
            <item name="dataScope" xsi:type="string">data</item>
            <item name="namespace" xsi:type="string">coupon_email</item>
        </item>
        <item name="template" xsi:type="string">templates/form/collapsible</item>
    </argument>
    <dataSource name="coupon_email_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
            <argument name="name" xsi:type="string">coupon_email_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">id</argument>
            <argument name="requestFieldName" xsi:type="string">id</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="base_fieldset">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="label" xsi:type="string" translate="true"> Details</item>
            </item>
        </argument>
        <field name="id">
            <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">Coupon</item>
                    <item name="formElement" xsi:type="string">input</item>
                </item>
            </argument>
        </field>        
    </fieldset>
</form> 
  • you should use a simple phtml template instead of ui-component – Piyush Feb 22 '18 at 6:00
  • We need this in our extension. Is it the right way? – Jancy Abraham Feb 22 '18 at 6:07
  • if you just want a simple form without any database values, you can call phtml template with form, it would be much easier – Piyush Feb 22 '18 at 6:09
  • Please share the sample code if you can – Jancy Abraham Feb 22 '18 at 6:17
  • you can do it the same way as we call template in frontend, you can check this reference – Piyush Feb 22 '18 at 6:20
1

For this, Your Data Provider should be like

<dataSource name="coupon_email_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Namespace\ModuleName\Model\DataProvider</argument>
            <argument name="name" xsi:type="string">coupon_email_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">id</argument>
            <argument name="requestFieldName" xsi:type="string">id</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>

Namespace\ModuleName\Model\DataProvider

And create Your DataProvider.php In Model Directory like Model/DataProvider.php

namespace Namespace\ModuleName\Model;


class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider
{
    /**
     * Get data
     *
     * @return array
     */
    public function getData()
    {
        return [];
    }

}

You will see the form then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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