0

I have a field which i don't want to show. But this field needs to be required.

this field should be populated when we click on specific button via ajax.

so we have something like that:

<form>
    ......
    ......
    <fieldset>
        <field name="myfield" formElement="textarea" sortOrder="120">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">Source</item>
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="disabled" xsi:type="boolean">true</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <label translate="true">My field</label>
                <dataScope>myfield</dataScope>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
            </settings>
        </field>
    </fieldset>
    <htmlContent name="html_content">
        <block name="html_content_block" class="Namespace\Module\Block\Adminhtml\Myblock">
            <arguments>
                <argument name="template" xsi:type="string">Namespace_Module::template.phtml</argument>
            </arguments>
        </block>
    </htmlContent>
</form>

html element is used to add button we need and javascript which contains ajax call.

This part does work as intended, however user can ignore this part and click on save button which leaves that field empty.

any idea on how to solve this ?

1 Answer 1

0

Try this way.

<field name="myfield" formElement="hidden">
    <settings>
        <dataType>text</dataType>
    </settings>
</field>

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.