2

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.

2

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"
data-bind="
    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 '18 at 11:57
  • why May i know? @Himanshu – Rutvee Sojitra Oct 5 '18 at 11:58
  • it's change all input as above added configuration. – Himanshu Oct 5 '18 at 11:58
  • @Himanshu i have edited my answer please apply it. it will work for perticular input field – Rutvee Sojitra Oct 5 '18 at 12:39
  • @Himanshu have you tried? – Rutvee Sojitra Oct 6 '18 at 2:19

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.