I know magento give max_text_length validation for validating length & print error message regarding it, but I want to add attribute in my input field as maxlength="5" so i can stop user to adding more value from it.

1 Answer 1


You can add below line in your:

                <item name="elementTmpl" xsi:type="string">Vendor_Module/form/element/input</item>
<item name="maxlength" xsi:type="number">5</item> <!-- it's a variable which is used on template side for getting values from it-->

add VENDOR/MODULE/view/adminhtml/web/template/form/element/input.html

               <input class="admin__control-text" type="text"
    event: {change: userChanges},
    value: value,
    hasFocus: focused,
    valueUpdate: valueUpdate,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': noticeId,
        id: uid,
        disabled: disabled,
        maxlength: maxlength // here we assign dynamic value '5' from maxlength var

after adding please run below commands:

php bin/magento setup:upgrade php bin/magento setup:static-content:deploy php bin/magento cache:flush

  • thank you for your answer, but this answer is not fulfilling the current scenario.
    – Himanshu
    Oct 5, 2018 at 11:57
  • why May i know? @Himanshu Oct 5, 2018 at 11:58
  • it's change all input as above added configuration.
    – Himanshu
    Oct 5, 2018 at 11:58
  • @Himanshu i have edited my answer please apply it. it will work for perticular input field Oct 5, 2018 at 12:39
  • @Himanshu have you tried? Oct 6, 2018 at 2:19

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.