Adventures with Power Apps: Fun with the NumberInput Modern Control

When I need to capture numeric data in a Canvas App I use the Classic control, TextInput.

I set the Format property to Number, which forces the TextInput control to only accept numeric characters.

The TextInput control also supports setting the value of the Default property to Blank().

Doing this allows me to force the User to enter a value whenever they clicked the Save Changes button.

Figure 1 – Code to check to see if numeric value provided

Lately I have been trying to use the Modern Controls instead of the Classic Controls.

To capture numeric data, I opted for the NumberInput control.

Instead of Default or Text the NumberInput control has a property called Value, which I set to Blank(), but for some reason it shows 0.

Figure 2 – Able to set Value to Blank()

Not the behavior I need.

I scoured the properties of the NumberInput control to see if there were any other options, only to come up empty handed.

So, if I want to stick with the Modern Controls, then I’ll need to use the TextInputCanvas.

The TextInputCanvas has a property for Type, but the only options available are Text, Search and Password. There is no Type for Number.

However, it does allow for the property Value to be set to Blank(), and displays an empty value, which is what I need to support in my Canvas App.

Figure 3 – Blank() shows empty value

Since I can’t control what the User enters, nothing prevents them from adding non-numeric characters, so I’ll have to add some logic in my Canvas App to manage this,

I set the OnChange property of the TextInputCanvas to UpdateContext({ctxHasError: !IsNumeric(TextInputCanvas1.Value) && !IsBlank(Trim(TextInputCanvas1.Value))}).

If ctxHasError is set to True an error message is displayed, and the Save Changes button is disabled.

Figure 4 – Display error message and disable button

This workaround, a bit of annoying inconvenience, allows me to continue to use the Modern Controls in my Canvas Apps.

Hopefully, sometime soon, support for Blank() will either come to the NumberInput control or Number will be added as an option for Type in the TextInputCanvas control.

If you have a better work around, please share!


Discover more from Matt Ruma

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *