1

I try to add text item to adminhtml UI component as described in docs:

<?xml version="1.0" encoding="UTF-8"?>
<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">...</argument>
    <settings>...</settings>
    <dataSource ...>...</dataSource>

    <fieldset name="..._form">
        ...
        <text name="text_example" template="ui/form/field">
            <settings>
                <label translate="true">Text Field Example</label>
                <visible>true</visible>
                <disabled>false</disabled>
                <elementTmpl>ui/form/element/text</elementTmpl>
                <value>The text value example</value>
            </settings>
        </text>

    </fieldset>
</form>

I have an error in browser:

1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): The XML in file "/.../view/adminhtml/ui_component/..._form.xml" is invalid:
Element 'value': This element is not expected.
Line: 63

Verify the XML and try again.
<pre>#1 Magento\Ui\Config\Reader->read() called at [vendor/magento/module-ui/Config/Data.php:102]
#2 Magento\Ui\Config\Data->initData() called at [vendor/magento/module-ui/Config/Data.php:136]
#3 Magento\Ui\Config\Data->get() called at [vendor/magento/framework/View/Layout/Reader/UiComponent.php:100]
#4 Magento\Framework\View\Layout\Reader\UiComponent->interpret() called at [vendor/magento/framework/View/Layout/ReaderPool.php:105]
...

I've checked text.xsd and ui_component.xsd and I don't see value attribute is defined there.

What is the right way to add text item to UI form?


These are the text items based on @Marius (first one) and @Shailesh Katarmal (second one) answers below:

enter image description here

Marius code should be slightly edited:

<text template="ui/form/element/text">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="inputName" xsi:type="string">text_example</item>
            <item name="value" xsi:type="string">Lorem ipsum ...</item>
        </item>
    </argument>
</text>

but Shailesh Katarmal code can be used as is.

Thanks, guys!

  • have you checked the XSD? – Philipp Sander Feb 20 at 12:40
  • yes, I've added links to XSD. – Alex Gusev Feb 20 at 12:53
1
   <field name="text_example" formElement="input">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="default" xsi:type="string">Default text here</item>
            </item>
        </argument>
        <settings>
            <label translate="true">Text Field Example</label>
            <visible>true</visible>
            <disabled>false</disabled>
            <elementTmpl>ui/form/element/text</elementTmpl>
        </settings>
    </field>
|improve this answer|||||
1

You are not allowd to use the tag value in that specific ui component.
If you want the input to have a default value then you should make your component look like this

    <text name="text_example" template="ui/form/field">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="default" xsi:type="string">Default text here</item>
            </item>
        </argument>
        <settings>
            <label translate="true">Text Field Example</label>
            <visible>true</visible>
            <disabled>false</disabled>
            <elementTmpl>ui/form/element/text</elementTmpl>
        </settings>
    </text> 

Apparently the example in the docs is wrong.
If you take a look a bit higher in the docs, in the "Configuration options" section you will see that there is no "value" element specified.

|improve this answer|||||
  • Element 'default': This element is not expected. :( – Alex Gusev Feb 20 at 13:00
  • Damn. Let me take another look. – Marius Feb 20 at 13:04
  • @AlexGusev I've updated the answer. Give it another try. – Marius Feb 20 at 13:06
  • PHP error is gone but JS error is came: knockout.js:3381 Uncaught ReferenceError: Unable to process binding "attr: function(){return { name:inputName,id:uid} }" Message: inputName is not defined at attr (eval at createBindingsStringEvaluator (knockout.js:2982), <anonymous>:4:18) ... – Alex Gusev Feb 20 at 13:35

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.