155
Views
3
Comments
Solved
[Input Mask React] How to set only fill-in 0 and positive number in integer input?
inputmask-react
Reactive icon
Forge asset by João Barata
Application Type
Reactive

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

2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

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

NeoLab_InputMaskTask.zip
UserImage.jpg
Film.T

Hi Sam,


I did follow your suggestion and it's working now.

Thank you very much for your kindly help :D

2021-03-18 21-03-15
Benjith Sam
 
MVP

You're welcome, Onthira.

Glad to help you :)


Kind regards,

Benjith Sam

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.