0

In UI component form, input fields(text and text area) are working allright. But when i try to replace it with a label it gives an error.

Code:

<field name="name">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string">Name</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">label</item>
            </item>
        </argument>
</field>

Error:

Exception #0 (Magento\Framework\Exception\LocalizedException): The requested component ("label") is not found. Before using, you must add the implementation.

I have researched a lot and couldn't find any worth mentioning solution.

  • You want to show some message on backend right? – Ronak Chauhan Nov 29 '17 at 10:21
  • @RonakChauhan infact i want to display some dynamic value as label inside form. – Wasim Bajwa Nov 29 '17 at 10:24
  • Currently works fine with input field but i have to replace it with label. – Wasim Bajwa Nov 29 '17 at 10:26
  • Hi @WasimBajwa, Did you find the solution – Jaisa Jun 30 '18 at 9:18
0

Magento 2 has it's own Ui module which contains all Form elements including Checkbox, CheckboxSet, Hidden, Input, MultiSelect, Radio, Select, Textarea, Wysiwyg. but It has not a Label element.

So If you want to add a field which contains dynamic text just for visible purpose then you can use container.

uiComponent form:

<container name="note_container">
   <argument name="data" xsi:type="array">
       <item name="config" xsi:type="array">
          <item name="sortOrder" xsi:type="number">30</item>
       </item>
   </argument>
   <htmlContent name="html_content">
       <argument name="block" xsi:type="object"><VendorName>\<ModuleName>\Block\Adminhtml\<CustomClass></argument>
        </htmlContent>
 </container>

Custom Class can contains your dynamic value in html or can call custom template file:

<?php

namespace <VendorName>\<ModuleName>\Block\Adminhtml;
use Magento\Framework\View\Element\Template;

class CustomClass extends Template
{
    protected $_template = 'custom.phtml';
}

custom.phtml can contains your visible data on form.

  • Looking at this link it seems to me that form element label exists. – Wasim Bajwa Nov 29 '17 at 10:39
  • Its Form elements which magento 2 supports not UiComponent of Magnto Supports – Ronak Chauhan Nov 29 '17 at 10:41
  • You can find the list of elements in UiComponent Module : Magento\Ui\Component\Form\Element – Ronak Chauhan Nov 29 '17 at 10:42

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.