cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
joshieboy
Helper III
Helper III

Disable submit based on multiple conditions

Hi,

I have a form whereby certain fields are visible based on a value selected in a dropdown.  As such, I cannot make ALL fields mandatory, as this will prevent the form from being submitted.  

So examples are:  

  1. If a user selects "Equipment Failure" from the Incident type sub category dropdown, the visible fields are "Was this registered" - which is a Yes/No field, and "Please provide more details" which is a textbox field
  2. If a user selects "Property Damage"  from the Incident type sub category dropdown, the visible fields are "Please provide an approx. value" and "Please provide more details"

And this behavior goes on based on the value selected in the Incident type sub category dropdown.

I would like to know how to prevent a user from clicking the Submit button, if any of the fields that become visible based on the selection in the Incident type sub category dropdown, is blank.  

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@joshieboy 

Glad that worked!

 

For the "Please provide more details field", the Required on that can be done like this:

   "|" & IncidentType_SubCategory.Selected.Value & "|" in "|Equipment Failure|Process Upset|Safety Critical Equipment and Sytems|" 

It's a shortcut to doing all of the OR (||) statements and to make sure there is an accurate match.  This should return true if the selected value is in that string.

Note, the "|" at the beginning and end of the selected value is just all about helping make sure that there is an exact match.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

6 REPLIES 6
RandyHayes
Super User III
Super User III

@joshieboy 

The easiest thing to do is to utilize the Form.Valid property of your form.  This will let you know that all required fields have been entered.

Now...considering that your requirements change based on the dropdown value, you simply need to put formulas in the Required properties of the datacards that you need.

So, for example, on the Was this registered" and "Please provide more details" datacards, set the Required property to your dropdown selection.

   yourIncidentTypeSubCategryDropdownControlName.Selected.Value = "Equipment Failure"

 

And for the "Please provide an approx. value" and "Please provide more details" datacards, set the Required property to:

   yourIncidentTypeSubCategryDropdownControlName.Selected.Value = "Property Damage"

 

Now, based on the above required properties, the Form Valid property will be true or false based on the dropdown.

You can then set the DisplayMode of your Submit button to the following:

   If(yourForm.Valid, Edit, Disabled)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hi @RandyHayes   this works like a charm.  Thank you. And I can leave the submit button as is, cause once those datacards are set to required based on the value, the fields become mandatory so a user cannot submit the form.

 

I forgot that there are certain fields that are tied to several options from the dropdown because its a generic field.  ie:  There is a fieldname called "Please provide more details" so if someone selects any of the following from the sub category dropdown, ["Equipment Failure","Process upset","Safety Critical Equipment and Systems","Indoor air quality","First Aid","Communicable disease","Ergonomic","Heat Illness","> 5 days","1-5 days","Vehicular","Medical Treatment","Personal Non-Occupational","Personal Occupational","Procedural deviation","Process Incident","Tier 1","Tier 2","Breach in Procedure","Cyber attacks","Threat","Unauthorised Intrusion","Tier 3","Tier 4","Activated","Failure In Service","Failure on Demand","Failure on Demand (testing)" -

 

the "Please provide more details field should be displayed.  I was trying to set this up as an array using your same formula above on this field so it would have read something like IncidentType_SubCategory.Selected.Value="Equipment Failure",""Process Upset","Safety Critical Equipment and Sytems" etc etc.  Not sure if this is the right or recommended way to do this.  It's not working also, but wanted to know what's the most efficient way of doing this, as I was able to use it as an array for the visible property on the field.  I thought the "required" property would have worked as well.  

RandyHayes
Super User III
Super User III

@joshieboy 

Glad that worked!

 

For the "Please provide more details field", the Required on that can be done like this:

   "|" & IncidentType_SubCategory.Selected.Value & "|" in "|Equipment Failure|Process Upset|Safety Critical Equipment and Sytems|" 

It's a shortcut to doing all of the OR (||) statements and to make sure there is an accurate match.  This should return true if the selected value is in that string.

Note, the "|" at the beginning and end of the selected value is just all about helping make sure that there is an exact match.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

@RandyHayes - Excellent.  Thank you so much again for this.  It works really well.  I also learned something new today with the "|" symbol.  Would have never thought to use it.

RandyHayes
Super User III
Super User III

@joshieboy 

Very good!!

 

Yes, this is a shortcut for something like this:

   someVal = "The Quick" || someVal = "Brown Fox" || someVal = "Little Brown Fox"

 

The key to keep in mind is to delimit it with something because, if you had this (combining just two of the above and testing with some val = "Brown Fox" - the middle one above) you would get erroneous results:

   someVal in "The Quick Little Brown FoxThis would return an erroneous true.

 

But, delimiting gives you more accuracy, but you also have to consider delimiting both sides:

   someVal in "|The Quick|Little Brown Fox|"  would give erroneous results of true if someVal was "Brown Fox".

 

   "|" & someVal & "|" in "|The Quick|Little Brown Fox|"  would give correct results of false if someVal was "Brown Fox".

 

And finally:

   "|" & someVal & "|" in "|The Quick|Brown Fox|Little Brown Fox|" would give correct result of true if someVal was "Brown Fox"

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes - the breakdown on that explanation above is well received.  It's even much clearer now.  Thanks again.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

Top Solution Authors
Top Kudoed Authors
Users online (47,176)