How to limit the input with number type
Question

Hi,

I am using reactive web. I have used input widget with number type, I have to set the maximum length 5, but maximum length property is not available for number type it is only available for text type.

mvp_badge
MVP
Solution

Hello Shrinjala,

I did various tests on this matter and I believe that I've found a solution for you :)


On the OnReady event of your screen, you can create an Event Listener for your Input Element using JavaScript.

document.getElementById("Input_Number").addEventListener("input", function() {
  Input_Number.value = Input_Number.value.slice(0, 5);
});


Basically, I'm using input event to control the allowed maximum length for that element using slice function. This will allow you to maintain your Input Type defined as Number.

Please refer to attached OML file.


Hope that this helps you!


Kind regards,

Rui Barradas

NumberMaximumLenght5.oml

Hi Rui,

This Script working very well.

I just adapt to affect all fields in screen.


If someone needs:


Many thanks mate


mvp_badge
MVP

Hi Paulo,

You are replying to and discussion of about 20.months ago and that already has a reply marked as solution.

Yes, I know. Thank you for the reminder ;)

mvp_badge
MVP

Hi,

That is correct you have to validate the entered value yourself. So let's say max length 5 then you can check in value <= 99999. Alternatively you could also validate the input using regular expression.

Regards,

Daniel

Hi,

Yes for "Number" type input field there is no provision to set the maximum length of the valus.

You can solve this problem using below steps:

- Use a action in "OnChanges" of the input field .

-Inside the action use "Regex Search" as shown in snap shot below

-Assign the value of "Regex Pattern" to the variable which is bind with you input field

Hope this will help you

Regards,

Vipasha

Vipasha Sharma wrote:

Hi,

Yes for "Number" type input field there is no provision to set the maximum length of the valus.

You can solve this problem using below steps:

- Use a action in "OnChanges" of the input field .

-Inside the action use "Regex Search" as shown in snap shot below

-Assign the value of "Regex Pattern" to the variable which is bind with you input field

Hope this will help you

Regards,

Vipasha

 its not working. I can use text type input but then i have to prevent the user to enter character, Please suggest solution.

 

mvp_badge
MVP

Hi Shrinjala,

You can try the following proposed solution with the use of some Javascript that runs on the onKeyDown event of the Input field.

Regards,

Nordin

Nordin Ahdi wrote:

Hi Shrinjala,

You can try the following proposed solution with the use of some Javascript that runs on the onKeyDown event of the Input field.

Regards,

Nordin

 

 I have tried this but its not working for me.

mvp_badge
MVP

Hi Shrinjala, 

can you share oml with us so can find whats the problem in your case if this solution is not working.


Regards

Rahul

mvp_badge
MVP
Solution

Hello Shrinjala,

I did various tests on this matter and I believe that I've found a solution for you :)


On the OnReady event of your screen, you can create an Event Listener for your Input Element using JavaScript.

document.getElementById("Input_Number").addEventListener("input", function() {
  Input_Number.value = Input_Number.value.slice(0, 5);
});


Basically, I'm using input event to control the allowed maximum length for that element using slice function. This will allow you to maintain your Input Type defined as Number.

Please refer to attached OML file.


Hope that this helps you!


Kind regards,

Rui Barradas

NumberMaximumLenght5.oml

Hi Rui,

This Script working very well.

I just adapt to affect all fields in screen.


If someone needs:


Many thanks mate


mvp_badge
MVP

Hi Paulo,

You are replying to and discussion of about 20.months ago and that already has a reply marked as solution.

Yes, I know. Thank you for the reminder ;)

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