2

i am adding form through ui_component but not save and back button are not showing

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/Ui/etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">sampleform_form.sampleform_form_data_source</item>
            <item name="deps" xsi:type="string">sampleform_form.sampleform_form_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Sample Form</item>
        <item name="layout" xsi:type="array">
            <item name="type" xsi:type="string">tabs</item>
        </item>
    </argument>

    <dataSource name="sampleform_form_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Magento\SampleForm\Model\DataProvider</argument>
            <argument name="name" xsi:type="string">sampleform_form_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">entity_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="sample_fieldset">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Sample Fieldset</item>
            </item>
        </argument>

        <!-- This field represents form id and is hidden -->
        <field name="entity_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">sampleform</item>
                </item>
            </argument>
        </field>

        <!-- This field has data type 'text' and standard 'input' form element and looks like input -->
        <field name="title">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">Some text</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">sampleform</item>
                </item>
            </argument>
        </field>
     </fieldset>
 </form>
2
  • add your edit.php block file code Aug 10, 2016 at 7:46
  • there is no block code.. Aug 10, 2016 at 7:47

1 Answer 1

3

adding this in data

<argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
        <item name="provider" xsi:type="string">sampleform_form.sampleform_form_data_source</item>
        <item name="deps" xsi:type="string">sampleform_form.sampleform_form_data_source</item>
    </item>
    <item name="label" xsi:type="string" translate="true">Sample Form</item>
    <item name="layout" xsi:type="array">
        <item name="type" xsi:type="string">tabs</item>
    </item>
    <item name="buttons" xsi:type="array">
    <item name="back" xsi:type="string">Namespace\Modulename\Block\Adminhtml\Category\Edit\BackButton</item>
    <item name="save" xsi:type="string">Namespace\Modulename\Block\Adminhtml\Category\Edit\SaveButton</item>

    </item>
</argument>

back button block

namespace Namespace\Modulename\\Block\Adminhtml\Category\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
 * Class BackButton
 */
class BackButton extends GenericButton implements ButtonProviderInterface
{
    /**
     * @return array
     */
    public function getButtonData()
    {
        return [
            'label' => __('Back'),
            'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
            'class' => 'back',
            'sort_order' => 10,
            'on_click' =>''
        ];
    }

    /**
     * Get URL for back (reset) button
     *
     * @return string
     */
    public function getBackUrl()
    {
        return $this->getUrl('*/*/');
    }
}

save button block

namespace Namespace\Modulename\Block\Adminhtml\Category\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
 * Class SaveButton
 * @package Magento\Customer\Block\Adminhtml\Edit
 */
class SaveButton extends GenericButton implements ButtonProviderInterface
{
    /**
     * @return array
     */
    public function getButtonData()
    {
        return [
            'label' => __('Save Block'),
            'class' => 'save primary',
            'data_attribute' => [
                'mage-init' => ['button' => ['event' => 'save']],
                'form-role' => 'save',
            ],
            'sort_order' => 90,
        ];
    }
}
9
  • Hello @Qaisar, I'm following your post to create save button, but it is not working, on click it is redirecting on same page without updating data, also post GenericButton.php code here, please reply? Jul 13, 2017 at 5:19
  • @VinayaMaheshwari i updated the answer with complete code Jul 13, 2017 at 5:33
  • Thanks for reply, but where are the GenericButton.php code and my save button showing module/index/index link instead /module/folder/save, while I have also added submit_url. Jul 13, 2017 at 5:46
  • @VinayaMaheshwari i don't have code right now but you can get idea from this file vendor\magento\module_cms\Block\Adminhtml\Block\Edit\GenericButton.php Jul 13, 2017 at 5:53
  • I got the idea from your another post https://magento.stackexchange.com/a/139643/14039 but why save button not working? Jul 13, 2017 at 5:55

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.