2629
Views
21
Comments
Solved
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.

2020-05-07 18-53-00
Rui Barradas
 
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
2023-08-28 07-00-10
Paulo Torres
Champion

Hi Rui,

This Script working very well.

I just adapt to affect all fields in screen.


If someone needs:


Many thanks mate


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Paulo,

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

2023-08-28 07-00-10
Paulo Torres
Champion
2024-07-05 14-16-55
Daniël Kuhlmann
 
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

2023-03-09 07-10-59
Vipasha Sharma

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

2020-12-07 13-51-26
Shrinjala Singh

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.

 

2021-08-12 11-00-27
Nordin Ahdi
 
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

2020-12-07 13-51-26
Shrinjala Singh

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.

2026-02-26 06-29-24
Rahul
 
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

2020-05-07 18-53-00
Rui Barradas
 
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
2023-08-28 07-00-10
Paulo Torres
Champion

Hi Rui,

This Script working very well.

I just adapt to affect all fields in screen.


If someone needs:


Many thanks mate


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Paulo,

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

2023-08-28 07-00-10
Paulo Torres
Champion
UserImage.jpg
Mahmoud Hassan

@Daniël Kuhlmann  ,

@Rui Barradas,


 I deploy your solution in my flow but I have this error .

000.png
2023-08-28 07-00-10
Paulo Torres
Champion

This mean you are running the script before your field loaded in DOM

UserImage.jpg
Mahmoud Hassan

I put the JS Code in the On Ready Action 

2023-08-28 07-00-10
Paulo Torres
Champion
UserImage.jpg
Mahmoud Hassan

Thank you for your interest 

I solve the problem 

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Why are we restarting a discussion more than 1,5 year old?

UserImage.jpg
Mahmoud Hassan

Because I have the same problem !!!!

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Don't think so because for the original poster a reply was the solution, apparently not for you.

Better to create a new discussion, and link to this old discussion.

UserImage.jpg
Vivekanandan Kulandasamy

Hi,

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

I would like to bring to your attention an issue encountered during the form submission process. We have implemented a JavaScript snippet using onready to assign and manipulate a value from an input box. However, it appears that the value set in the variable is not being recognized or submitted with the form.

Despite assigning the value from the input field using JavaScript, the backend is not receiving the updated value upon form submission. This is affecting the proper capture of user input data.

Kindly review the script implementation and advise on any necessary changes to ensure that the dynamically assigned value is correctly submitted.

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