Business Applications, PowerApps, Uncategorized

Multiple ways to implement the required field validation in PowerApps. Part 2.

The beginning is here: Multiple ways to implement a required field validation in PowerApps. Part 1.

And this is where it’s getting weirder …

3.  I just know you can do it this way. Don’t ask me why. Data source level validation.

Repeat all steps from 2 for the data source changes up to the Then Save Entity. This time I do it for the Description field. Go back to your app. On the Edit form for the Description card on the Advanced tab Unlock to change properties.

v21

For the Required property specify the following:

DataSourceInfo(Contacts,DataSourceInfo.Required,”description”)

v22v23

4.   Custom required validation. App level validation.

 

For the scenario where you have to mark a field required or not based on the selection of another field we will implement the custom required field validation:

In my case either Mobile or Business Phone field is required.

v24

Let’s use the context variable IsPhoneSpecified to store the flag if one or both phone fields are populated.

I put the script OnVisible of the Screen1 control:

UpdateContext({IsPhoneSpecified:0});UpdateContext(If(IsBlank(mobilePhone.Text),{IsPhoneSpecified: IsPhoneSpecified + 1},{IsPhoneSpecified: IsPhoneSpecified}));UpdateContext(If(IsBlank(businessPhone.Text),{IsPhoneSpecified: IsPhoneSpecified + 1},{IsPhoneSpecified: IsPhoneSpecified }))

v25

For the mobilePhone control Advanced properties OnChange add the following:

UpdateContext(If(IsBlank(mobilePhone.Text),{IsPhoneSpecified: IsPhoneSpecified + 1},{IsPhoneSpecified: IsPhoneSpecified – 1}))

v26

For the businessPhone control Advanced properties OnChange add the following:

UpdateContext(If(IsBlank(businessPhone.Text),{IsPhoneSpecified: IsPhoneSpecified + 1},{IsPhoneSpecified: IsPhoneSpecified – 1}))

Add a new error label to the form:

v27

Set Visibility of the error label to the expression below:

v28

This is how it works:

v29v210v211

Looking good! Unfortunately, it doesn’t stop a user from the actual form submission. So the last step to get it fully working will be to trigger the Submit button visibility based on the IsPhoneSpecified flag value:

IsPhoneSpecified<=1

v212v213v214

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s