web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Looking for a cleaner ...
Power Apps
Answered

Looking for a cleaner way to prevent submission of a form until a field equals a specific value (100)

(0) ShareShare
ReportReport
Posted on by 383

I've created a canvas app, and part of it has fields for 6 different subsidiaries. The user is asked to enter what percentage of time they spend working for each of the subsidiaries. The total needs to add up to 100%, and I'd like to validate that before allowing the form to be submitted.

 

Currently I have a hidden label named lblHourSum, which has the following set in the text property:

 

 

 

Value(
 (DataCardValue5.Text) +
 (DataCardValue6.Text) +
 (DataCardValue7.Text) +
 (DataCardValue8.Text) +
 (DataCardValue9.Text) +
 (DataCardValue10.Text)

)

 

 

 

 

Then at the bottom of my form I have another text label which stays visible until the total reaches 100%, named lblNotice:

 

TrayH_0-1679318629442.png

 

Here is the visible property of lblNotice:

 

 

 

!(Value(lblHourSum.Text)=100)

 

 

 

This works, but feels clunky to me. It has also has the problem of not actually preventing the user from submitting if the value doesn't equal 100, as I don't have any mechanism in place to stop that.

 

Instead of having lblNotice visible at all times until the total reaches 100, I'd instead like to have a notice come up only if the user tries to submit when the value of lblHourSum is anything other than 100. This could be either through the red error message banner at the top or by using the existing lblNotice. But I also need it to prevent submission if not equaled to 100.

 

Hopefully that makes sense. Thanks for any direction you can provide.

Categories:
I have the same question (0)
  • Verified answer
    mmollet Profile Picture
    3,187 on at

    I like to build a progress bar that visually shows the user where they are at. I will link a question that I answered that shows how to do this. I usually make the submit button pop up in the same way you do but with the display mode instead of visibility property. I would set your submit buttons DisplayMode to

    If(Value(lblHourSum.Text)=100, ViewMode.Edit, ViewMode.View)

    This will basically grey out your submit button until the values add to be 100. At that point it will be able to be clicked again. Hope this helps!

     

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Count-number-of-empty-fields-in-a-form-using-Power-Apps/m-p/2052783#M513312

  • TrayH Profile Picture
    383 on at

    Thanks, I like that! I've got the progress bar but I'm missing one small thing which is probably a really easy fix. 

     

    I set the Text property of front label to lblHourSum, and it's displaying it as expected. But I'd like to get a trailing percent sign added so it's shown as a percentage instead of just the whole number. Tried to do something like lblHourSum "%" but that doesn't work.

    TrayH_0-1679322077614.png

    TrayH_1-1679322090950.png

    Now that I think about it, I could just add an image of the percent symbol next to the label. That's what I'm doing in the questions.

     

     

  • mmollet Profile Picture
    3,187 on at

    Text(lblHourSum,"#0.00%")

    This will convert your lblHourSum to a string (it already is here but this also allows string formatting) then it will format your string to fit the 2nd string passed in: "#0.00%". Where there is a '#' it will only put a number there if there is a non 0 digit, where there is a '0' it will add a zero even if there is no valid non 0 digit, then it will add the '%' sign at the end. You can change this to be whatever format you want. If you just want rounded to whole numbers and the % sign then use "##%" I think.

  • TrayH Profile Picture
    383 on at

    Thanks. I never could get it to show the percent sign in the field itself as text, but I simply placed an image of the percent symbol in there and it looks fine. Thanks again for this tip, I can definitely see using it with other apps in the future.

    TrayH_0-1679337162051.png

     

  • mmollet Profile Picture
    3,187 on at

    Function calls work from the inside out. Since you are trying to format numbers but have a label which is of data type text/string you will need to cast the string into a int/float value first before you give it to the text function to format. For this reason you need to get the Value(YourTextLabel) then pass that into the text function as parameter one.

    Value function: Value(your text to convert to a value) -> example Value("845") would take the string "845 and give you the output 845 as a number you can do math with.

    Text Function: Text(number value, formatting options) -> this can handle numbers and times and others but you are using it for a number (float/decimals) and so you would pass in your number as the first parameter and then the format for that number as the second. Ex1: Text(0.834,"##.00%") -> .83% if you want a 0 in front every time you would use Text(0.834,"#0.00%") -> 0.83%. Below is a screenshot that I hope will help as well.

    Screenshot 2023-03-20 at 2.06.04 PM.png

     

  • TrayH Profile Picture
    383 on at

    That did it! Thank you!

  • NickMerrick Profile Picture
    419 Super User 2024 Season 1 on at

    to save on control count, you could have an svg loading bar instead of two labels, using a variable to control the percentage filled. would also allow for changing screensizes without errors.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard