5
<item name="config" xsi:type="array">
    <item name="label" xsi:type="string" translate="true">My Custom Filed</item>
    <item name="dataType" xsi:type="string">text</item>
    <item name="formElement" xsi:type="string">input</item>
    <item name="source" xsi:type="string">model_name</item>
    <item name="dataScope" xsi:type="string">my_custom_field</item>
    <item name="sortOrder" xsi:type="number">1</item>
    <item name="validation" xsi:type="array">
        <item name="required-entry" xsi:type="boolean">true</item>
        <item name="no-whitespace" xsi:type="boolean">true</item>
        <item name="validate-pattern" xsi:type="string">/^[a-z][a-z0-9_.-]$/i</item>
    </item>
</item>

I want to display a customized error message in Magento 2 admin form while I use pattern validation it gives invalid input but I want a customized message like You should enter a decimal value in place of it. Thanks

0

1 Answer 1

0

Pass the item as array and value. It was working on Magento 2.3.1.

<!-- ... -->
<item name="validation" xsi:type="array">
    <item name="required-entry" xsi:type="array">
        <item name="validate" xsi:type="boolean">true</item>
        <item name="message" xsi:type="string">Custom error message for required field.</item>
    </item>
    <item name="pattern" xsi:type="array">
        <item name="validate" xsi:type="boolean">true</item>
        <item name="value" xsi:type="string">/^[A-Za-z]+[A-Za-z0-9_]+$/i</item>
        <item name="message" xsi:type="string">Custom error message for pattern validation</item>
    </item>
</item>
<!-- ... -->

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.