Hi everyone,
I'm using the InputMask React and now I need to set integer input that can fill in only 0 and positive numbers.
Would you please suggest how to set the component to allow only a positive integer?
Best Regards,
Onthira
Hi Onthira,
One of the solutions would be to introduce your own custom defined input mask block in the library module referencing the InputMask JS.
Implementation Steps:
1) Define a block called MaskNumber_OnlyPositive in the InputMask React Component Library module
2) Define a JS node with the below-mentioned script in the MaskNumber_OnlyPositive block's OnReady action flow
var selector = document.getElementById($parameters.Input); if (selector && (selector.tagName === 'TEXTAREA' || selector.tagName === 'INPUT')) { Inputmask.extendAliases({ 'positiveNumber': { alias: "integer", placeholder: $parameters.Placeholder, allowPlus: false, allowMinus: false } }); Inputmask("positiveNumber").mask(selector); }
3) Reference MaskNumber_OnlyPositive block in the UI module, and associate it with an input to mask the user input value.
Documentation Link: https://github.com/RobinHerbots/Inputmask#set-defaults
Demo Screen: OnlyPositive_InputMask
Refer to the attached oml's.
I hope this helps you!
Kind regards,
Benjith Sam
Hi Sam,
I did follow your suggestion and it's working now.
Thank you very much for your kindly help :D
You're welcome, Onthira.
Glad to help you :)