cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Eduardo_GzzC
Level: Powered On

Forcing Integer input for a Text Input Control

Hi,

 

I'm trying to force a Text Input control to accept only integers but it isn't working so far.

Right now I'm using the following code in the OnChange property of the Text Input control:

If(Value(TextInput.Text ) <> RoundDown(Value(TextInput.Text),0),
Set(resetTextBox, true));Set(resetTextBox, false)

The Reset property of this control is set to the resetTextBox variable.

 

Has anyone accomplished this in a different way?

 

 

5 REPLIES 5
Highlighted
Super User
Super User

Re: Forcing Integer input for a Text Input Control

Hi @Eduardo_GzzC 

Could you explain what it is about your code that doesn't work?

In the test that I carried out, the text input control accepts whole numbers. If the input value includes numbers after the decimal point, the text input control clears itself. Are you expecting some different behaviour?

Super User
Super User

Re: Forcing Integer input for a Text Input Control

Hi @Eduardo_GzzC 

 

You can try to update the Format property of your TextInput to TextFormat.Number. It will only allow to enter the numbers.
MicrosoftTeams-image (73).png

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Super User
Super User

Re: Forcing Integer input for a Text Input Control

Hi @yashag2255 

I think the issue with the TextFormat.Number format is that it allows fractional numbers (eg 2.55). As I understand, @Eduardo_GzzC wants to allow only whole Integer numbers.

Super User
Super User

Re: Forcing Integer input for a Text Input Control

Hi @timl , yes there is a limitation where it allows the decimal point but at the same time we can reset the control as soon as a non-number character is identified, user does not need to move out of the control to see the changes/ reset the textbox. And for removing the decimal value, I think the code @Eduardo_GzzC  used will suffice the requirement. 

 
 @Eduardo_GzzC are you getting any error? I tried out your code and it is resetting the text input control when the user clicks out somewhere else on the screen. But with TextFormat.Number, your input will reset as soon as a character is detected.
 
Thoughts?
Eduardo_GzzC
Level: Powered On

Re: Forcing Integer input for a Text Input Control

Hi, thanks for the answers so far. The code is working after I click outside as expected. I just wanted something that prevents even typing the decimal point. Like when you choose a number as a format and it won't accept text.

 

I guess it would have to be like this for the moment until I find a workaround.