cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jchicky
Advocate I
Advocate I

How can I restrict the range of values allowed in a text input box?

Similar to how the slider control allows me to configure a min and max value, how can I achieve the same with a text input box that is set to allow numbers? For example, I want to restrict the user to only enter a number from 0-100.
7 REPLIES 7
Sienna
Resident Rockstar
Resident Rockstar

Just set the textbox to format number and Maximum lenght to 3

text.png

Anonymous
Not applicable

Thank you for the suggestion. I gave it a shot, but users are able to enter numbers from 101 to 999. I am hoping to cut them off at a specific number, such as 100 in my example.

In that case try to add in OnChage property of your TextInput 

 

UpdateContext({restrict: Value(TextInput1.Text)}); If(restrict>100, UpdateContext({restrict: 100}))

 

And change Default property of the TextInput to

 

restrict

 

This will automaticaly change the value of that TextInput to 100 when user type value larger then 100. That is the only way you can do it

ChoiceDude
Regular Visitor

I don't know if you already solved this issue, but I had this exact situation and I prevented the user from submitting the form if they entered a number into the text box (called Ans211) that was higher than 100:

 

  • On the "Submit" button, I had the following code on the OnSelect field:
    • If(Value(Text(Ans211)) > 100, " ", Submit(Form211); Navigate(...)
      • This disables the submit button unless the user has entered a number which is less than or equal to 100.
  • I also had a text box which read "Please enter a number between 1 and 100." which had the following code on the Visible field:
    • Value(Text(Ans211)) > 100

 

TL;DR: Use the Value and Text functions to extract the number that the user has entered (syntax: Value(Text(TextBox)) ) and use an If function to prevent the submit button from working unless the number is within your specified parameters. A pop-up warning is also easy and helpful to throw in there. 

Brian-Hamilton
Advocate I
Advocate I

I had a similar problem. In my case, I had a Rich Text Editor box to which I wanted to add a character limit. Here's what I did.

 

Create a Rich Text Editor with the following properties:

BorderColor: If(Len(RichTextEditor.HtmlText)>1500, Color.Red, Color.Black)

 

Create a label with the following properties:

Text: "Label (" & 1500 - Len(RichTextEditor.HtmlText) & " character limit)"

Color: If(Len(RichTextEditor.HtmlText)>1500, Color.Red, Color.Black)

 

Create a button with the following properties:

On Select: If(Len(RichTextEditor.HtmlText)>1500, Notify("RichTextEditor exceeds 1500 character limit", NotificationType.Error), SubmitForm(Form))

 

There may be a more elegant way to achieve the same results, but this worked for me.

HafsteinnElvar
New Member

Hi

I had the same issue. trying to limit the values for seconds to maximum 59. I did this:
In Onchange -> If(CompleteMin/1>59, Reset(CompleteMin), false)

All values below 60 stays in the field but when I try higher the field resets.

Had to divide the "CompleteMin" field with 1 to convert it from control to value.

With best regards

Hafsteinn

Great.

 

In my case I am trying to do the UpdateContext only in one Gallery Item and them Patch to a sharepoint list, like bellow.

 

UpdateContext({restrict: Value(TextInput1.Text)});;
If(restrict>ThisItem.Extra_Forecast; UpdateContext({restrict:ThisItem.Extra_Forecast}));;
Patch(App_ExtraForecast; ThisItem;{Equalization_Seller:Value(TextInput1.Text)})

 

It happens that when I put the UpdateContext and If condition, also as the restrict in the Default function, when I change an Text Input, it changes in all gallery item.

How can I do this UpdateContext only in the selected item of the gallery? 

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,535)