1

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.

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

1 Answer 1

1

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.

3
  • Looking at this link it seems to me that form element label exists. Commented Nov 29, 2017 at 10:39
  • 1
    Its Form elements which magento 2 supports not UiComponent of Magnto Supports Commented Nov 29, 2017 at 10:41
  • You can find the list of elements in UiComponent Module : Magento\Ui\Component\Form\Element Commented Nov 29, 2017 at 10:42

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.