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
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– Himanshu2018-10-05 11:57:02 +00:00Commented Oct 5, 2018 at 11:57
-
why May i know? @HimanshuRutvee Sojitra– Rutvee Sojitra2018-10-05 11:58:04 +00:00Commented Oct 5, 2018 at 11:58
-
it's change all input as above added configuration.Himanshu– Himanshu2018-10-05 11:58:44 +00:00Commented Oct 5, 2018 at 11:58
-
@Himanshu i have edited my answer please apply it. it will work for perticular input fieldRutvee Sojitra– Rutvee Sojitra2018-10-05 12:39:34 +00:00Commented Oct 5, 2018 at 12:39
-
@Himanshu have you tried?Rutvee Sojitra– Rutvee Sojitra2018-10-06 02:19:38 +00:00Commented Oct 6, 2018 at 2:19