1

I am new to Magento 2.

I am trying to make a field that can only accept numbers for Sort Order field on UI Component Form

I need help

2

you just need to add

<item name="validate-number" xsi:type="boolean">true</item>

in your specific field in ui_component

  • Thank you if i need max_lenght and min_length.. how can i achive this – Waqar Ali Apr 19 at 10:54
  • max_length of what? – Asad Khan Apr 19 at 10:54
  • first try this code it will only accept the numbers – Asad Khan Apr 19 at 10:55
  • i have done that and its working perfectly.. thank you – Waqar Ali Apr 19 at 10:55
  • i want to limit user to user numebrs between 10 and -10 – Waqar Ali Apr 19 at 10:56
0

Just want to add this one, if you want to validate user input if it is within the range of -10 to 10.

<item name="validation" xsi:type="array">
    <item name="validate-digits" xsi:type="boolean">true</item>
    <item name="validate-digits-range" xsi:type="string">-10-10</item>
</item>

Note: use validate digits instead of validate number when you are validating integers otherwise use number when you are validating number input with decimals.

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.