문제

I have implemented admin form using UI component. In that, I have 3 separate tabs. Among 3, I have displayed one tab using custom phtml file by using following code in ui component form xml file

<fieldset name="custom_fieldset" sortOrder="30">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">Manage Titles</item>
            <item name="collapsible" xsi:type="boolean">true</item>
        </item>
    </argument>
    <container name="custom_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">Namespace\Module\Block\Adminhtml\Module\Labels</argument>
        </htmlContent>
    </container>
</fieldset>

But when I click on save button I am not getting any data in save controller post variable from this particular phtml file. I am getting data of other 2 tabs which implemented using field tag as we do normally with ui component.

This is my phtml file code :

<div class="fieldset-wrapper" id="manage-titles-wrapper">    
<div class="fieldset-wrapper-content in collapse" id="manage-titles-content">
    <fieldset class="admin__fieldset fieldset">
        <div class="admin__control-table-wrapper">
            <table class="admin__control-table" id="attribute-labels-table">
                <thead>
                <tr>
                    <?php foreach ($block->getStores() as $_store): ?>
                        <th class="col-store-view"><?= /* @escapeNotVerified */ $_store->getName() ?></th>
                    <?php endforeach; ?>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <?php foreach ($block->getStores() as $_store): ?>
                        <td class="col-store-view">
                            <input class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>" type="text" name="frontend_label[<?= /* @escapeNotVerified */ $_store->getId() ?>]" value="" <?php if ($block->getReadOnly()):?> disabled="disabled"<?php endif;?>/>
                        </td>
                    <?php endforeach; ?>
                </tr>
                </tbody>                    
            </table>
        </div>
    </fieldset>
</div>

This is my block code

    <?php

namespace Namespace\Module\Block\Adminhtml\Module;

class Labels extends \Magento\Backend\Block\Template
{
    /**
     * Block template
     *
     * @var string
     */
    protected $_template = 'labels.phtml';

    /**
     * AssignProducts constructor.
     *
     * @param \Magento\Backend\Block\Template\Context  $context
     * @param array                                    $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }

    /**
     * Retrieve stores collection with default store
     */
    public function getStores()
    {
        return $this->_storeManager->getStores();
    }
}

Any help into this will be highly appreciable.

Thanks.

도움이 되었습니까?

해결책

You have to just add

data-form-part="forrname_form" in your input filed forrname_form it's must be similar with your ui form name

your code shold be like now:

    <tr>
                <?php foreach ($block->getStores() as $_store): ?>
                    <td class="col-store-view">
                        <input data-form-part="forrname_form" class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>" type="text" name="frontend_label[<?= /* @escapeNotVerified */ $_store->getId() ?>]" value="" <?php if ($block->getReadOnly()):?> disabled="disabled"<?php endif;?>/>
                    </td>
                <?php endforeach; ?>
            </tr>

The data-form-part HTML element’s attribute allows you to include the element’s value to the data submitted to the server.

다른 팁

Adding to Rutvee's answer, it is also possible to set the data-form-part in code like so:

$fieldset->addField('example_field', 'text', [
    'label' => __('Example Field'),
    'name' => 'example_field',
    'data-form-part' => 'sales_rule_form'
]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top