cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HendosMark
Frequent Visitor

Advice for Conditionally Required Fields

Hi

 

I'm again hoping you guys out there can assist me with a problem I am having in validating data entered into an app. My scenario is as follows:

 

- I have 1 sharepoint list which contains all my fields for my app

- My app is made up of 7 different screens, all of which contain an edit form

- On screen 1 the edit form has a SUBMIT function

- All other screens use PATCH, using the LastSubmit.ID from Edit form 1

- In the beginning, all screens have NO validation, as I want users to be able to navigate all screens and enter in data where they feel applicable

- Only when a user presses a SUBMIT button on the last screen should validation start, and to do this I have done the following:

 

1. OnSelect for the Submit button = Set(varRequired,true)

2. All data cards in all forms that are required have a Required property of = if(varRequired = true,true,false)

 

The validation works fine for Edit Form 1 with the SubmitForm function, however none of the Patch forms validate.

 

I am happy to return users to Page 1 and cycle through all screens to check their submission on each form and see errors, however ideally I want the SUBMIT button on the last screen to check all edit forms and return message of which fields are required, and only when all errors are fixed navigate to a success screen

 

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @HendosMark ,

Do you set the fields within your Edit forms as Required via setting the Required property of the Data card in the Edit form?

Do you want the validation also to be worked when you use Patch function to submit the rest of Edit forms data?

 

If you want the the validation also to be worked when you use Patch function to submit the rest of Edit forms data, I afraid that there is no way to achieve your needs.

The Required property of the Data card control within the Edit form only works when you use SubmitForm() function to submit form data. When you use Patch function to submit your form data, the error message would not show up.

The user @ck25415 has faced same issue with you, please check my response within the following thread:

https://powerusers.microsoft.com/t5/General-Discussion/Required-field-error-message-not-displayed-wh...

 

As an alternative solution, please take a try with the following two solutions:

1. Set these fields in your SP list itself as Required field:

You could set these fields in your SP list itself as Required field, then modify your Patch function as below:

If(
    !IsEmpty(
Errors(
'YourSPList',
Patch('YourSPList', EditForm1.LastSubmit, Form2.Updates) /* <-- Type your Patch formula here */
)
), Notify(First(Errors('YourSPList')).Column & " " & First(Errors('YourSPList')).Message, NotificationType.Error) )

Please consider take a try with the first solution mentioned within above thread I provided, then check if the issue is solved.

 

2. You could add a If function to your formula, to check if the specified Required field is not populated with values, if true, show an error message:

Modify your Patch formula as below:

If(
   IsBlank(DataCard1InForm2.Text),        /* <-- Check if the specific Required field text box is populated with values */
   Notify("The Column1 is a Required field, please type a valid value within it!", NotificationType.Error),
IsBlank(DataCard2InForm3.Text),
Notify("The Column2 is a Required field, please type a valid value within it!", NotificationType.Error),
...
... Patch('YourDataSource', Defaults('YourDataSource'),{Title: "PowerApps R", ...}) /* <-- Type your Patch formula here */ ) 

Note: The DataCard1InForm2 , DataCard2InForm3 ... represents the different data cards in your different Edit forms.

Please consider take a try with the second solution within the above thread I provided.

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
LRVinNC
Resident Rockstar
Resident Rockstar

Not sure if there is something else preventing the validation, but you should only need to set the Required property of your data cards to varRequired, not to an if statement.  You set the value of varRequired to true or false as needed (setting it to false when your application starts then to true when the submit button is used and back to false before you start another edit)  Then the Required property of a data card simply looks to see what the value of varRequired currently is to handle turning the required validation on or off.  

LRVinNC

------------------
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
jhall
Skilled Sharer
Skilled Sharer

I had a very similar application a year ago w/ lots of fields and had to juggle things a bit.  However, I did approach things differently.

First off, I'd ask about your Forms on the latter pages.  What are they linked to?  Which is followed by: how are you ensuring the fields are valid?  If you aren't linking those later fields to some form of Collection or global variable, then I'm not sure youre methodology will work.

I will admit, I started my first app the way you describe and quickly abandoned it.  I instead, did one Form but only displayed fields for the Form if you were on a "virtual page" within that screen.  So user would hit Next -> and new fields would be displayed (but they were on the same PowerApps "Screen").  I kept a global variable to see if the first page had been submitted which determined if that page should be in New() or Edit() mode for the Form.  This meant I could Submit() the initial New form (first virtual page) and then Submit() a form that was now in Edit mode (2nd and beyond virtual pages).  Validation was also keyed to the Visible property which was keyed to the Page variable (but you could do that differently).

This kept me from having to manually Patch() records.

I believe you could do a similar setup (even retaining your multi-Screen design) by having the Form() from your first screen copied/pasted and just doing some logic for if you are editing vs. creating a record.

If you did this, then you could also have an "optional" final page that not only informed you of the errors, but you could display all of the fields that have issues using the same method on a single Screen/Form.

 

v-xida-msft
Community Support
Community Support

Hi @HendosMark ,

Do you set the fields within your Edit forms as Required via setting the Required property of the Data card in the Edit form?

Do you want the validation also to be worked when you use Patch function to submit the rest of Edit forms data?

 

If you want the the validation also to be worked when you use Patch function to submit the rest of Edit forms data, I afraid that there is no way to achieve your needs.

The Required property of the Data card control within the Edit form only works when you use SubmitForm() function to submit form data. When you use Patch function to submit your form data, the error message would not show up.

The user @ck25415 has faced same issue with you, please check my response within the following thread:

https://powerusers.microsoft.com/t5/General-Discussion/Required-field-error-message-not-displayed-wh...

 

As an alternative solution, please take a try with the following two solutions:

1. Set these fields in your SP list itself as Required field:

You could set these fields in your SP list itself as Required field, then modify your Patch function as below:

If(
    !IsEmpty(
Errors(
'YourSPList',
Patch('YourSPList', EditForm1.LastSubmit, Form2.Updates) /* <-- Type your Patch formula here */
)
), Notify(First(Errors('YourSPList')).Column & " " & First(Errors('YourSPList')).Message, NotificationType.Error) )

Please consider take a try with the first solution mentioned within above thread I provided, then check if the issue is solved.

 

2. You could add a If function to your formula, to check if the specified Required field is not populated with values, if true, show an error message:

Modify your Patch formula as below:

If(
   IsBlank(DataCard1InForm2.Text),        /* <-- Check if the specific Required field text box is populated with values */
   Notify("The Column1 is a Required field, please type a valid value within it!", NotificationType.Error),
IsBlank(DataCard2InForm3.Text),
Notify("The Column2 is a Required field, please type a valid value within it!", NotificationType.Error),
...
... Patch('YourDataSource', Defaults('YourDataSource'),{Title: "PowerApps R", ...}) /* <-- Type your Patch formula here */ ) 

Note: The DataCard1InForm2 , DataCard2InForm3 ... represents the different data cards in your different Edit forms.

Please consider take a try with the second solution within the above thread I provided.

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Awesome

 

I've had a quick play, and i've decided to move forward with the IF statement, however instead of waiting for validation when onselect of the save button, i'll instead disable the save button until all required fields are completed using the isblank function

 

Great stuff, thanks @v-xida-msft @jhall @LRVinNC for all getting in touch, much appreciated!

Hi @HendosMark 

 

I have had many good hours on the same topic and are now making use of the Valid property that could be used for each card and for the form. 

 

Please see below video on how to do validation before or without submitting the forms.

 

https://youtu.be/7O8HCz37Q0A

 

Dawid van Heerden
Follow on Twitter: @davestechtips
Subscribe to YouTube: https://www.youtube.com/davestechtips?sub_confirmation=1
**If you found this reply helpful, please mark this as the answer to close the topic and make it easier to find for other people with similar questions.

 

Dawid van Heerden

Follow on Twitter: @davestechtips

Subscribe to YouTube: https://www.youtube.com/davestechtips?sub_confirmation=1

**If you found this reply helpful, please mark this as the answer to close the topic and make it easier to find for other people with similar questions. AND we get points for it 😉

dmclaughlin
Post Patron
Post Patron

I have a powerapp form and need to have a field called taxid turned on to be a required field only if the field export = "Yes".  I've tried in the form in the data area of the field taxid and the advanced are and required setting several If statements on the export field and could still save without entering data.  I then tried just putting true in the taxid  advanced required setting and same thing could save without data.  So now I'm wondering if that required area of a field even works at all?  Any suggestions?

If Export is  stored as a boolean (true/false) field (even though it may appear as a Yes/No), you'll need to actually test for True, not Yes.  You can test boolean values easily with just the name of the field.  So, in the required property you would simply put the name of your variable (Export) - no if is needed - it simply means, Required is true when Export is true.  (To test for false use !Export  which means not Export or false).  Hope this helps.

LRVinNC

------------------
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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.

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 (3,758)