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

How to Trigger Field Validation Error Messages on Multi-Page Forms

I have created a three page SharePoint list form that has all but three fields as required. However, when I try to submit the the form with some fields being empty, it does not alert the user that the field is empty and the form is still submitted. Currently, I have a save button at the end of the form with the following code used OnSelect:

 

Patch('Contingent Worker Onboarding',Defaults('Contingent Worker Onboarding'),CWInfo_Form.Updates,JobInfo_Form.Updates,OtherCompany_Form.Updates)

Ideally I would like for it to set off the Error notifications that are trigged by default when using OnSubmit as shown below. Right now it I can only get this to work using the default Save button in SharePoint and it only works for the first page.

 

 

sampleerror.png

 

 

 

 

 

 

 

 

 

 

 

 

I've tried searching online but I cannot find any good examples/best practices on how to accomplish this efficiently. Everything I found shows how to use Patch on a Multi-page form but not how to manage validations. I also, have the following questions:

 

1. Would it be better to validate the fields after the entire form is filled out? Or would it be best to validate these fields when they click on the next button before they go to the next page?

2. Since my fields are required when I use Patch should I explicitly add every field in order for the validation to work or should continue to use what I am using (see code above).

3. I noticed when I use my custom save button to submit, when the user goes back to view/edit the form all but the first form fields are blank eventhough in the SharePoint list they all have values. How can I fix this?

 

Here are screenshot of my form for more information:

 

All the required fields are set on the List level and on the PowerApps form

 

Columns.png

 

SharePoint Integration Settings.

 

SharePointIntegration.png

 

First Page of the Form

 

Screen: CWInfo

Form: CWInfo_Form

 

 

Next Button OnSelect

NewForm(JobInfo_Form); Navigate(JobInfo,ScreenTransition.Fade)

 

 

Second Page of Form

Screen: JobInfo

Form: JobInfo_Form

 

JobInfo.png

 

Next Button OnSelect

NewForm(OtherCompany_Form); Navigate OtherCompany,ScreenTransition.Fade)

 

 

Third Page of Form

Screen: OtherCompany

Form: OtherCompany_Form

 

 

 

Save Button (Same as Above):

Patch('Contingent Worker Onboarding',Defaults('Contingent Worker Onboarding'),CWInfo_Form.Updates,JobInfo_Form.Updates,OtherCompany_Form.Updates)

 

Any advice would be greatly appreciated!

14 REPLIES 14

oooooohhH!! Thats pretty slick @richcoresln !!
Does that work for partial form submissions?
Example:

  • 60 field form
  • Split into "Subforms" for usability
  • Can you check .Valid on a certain section (Form1), then, IF Valid, move to next section (Form2)
  • Repeat, but have each SubForm submit results (Patch, really) to the original record?

That sounds useful.

@seadudeyes that is kind of what is being achieved by using this:

 

If(!Form1.Valid, SubmitForm(Form1), Navigate(CustomFormScreen2));

This is on a "CustomFormScreen1" screens "Next" buttons "OnSelect" function.

This screen would not contain the entire data set available to Form1, with "CustomFormScreen2" containing a "Form2" with the remaining data set.

This could of course be repeated n number of times as necessary (achieving subforms).

 

We will only be calling Submit for the form when it is not valid; this results in the internal form validation being carried out (and failing as expected) and the forms error messages being displayed, but the submit function does not succeed. To answer your question, a form only seems to validate fields which have been added.

I agree this seems counter-intuitive which is why I would be interested if there was a cleaner way of achieving this (such as a form.Validate() function, however it does not appear so: https://powerusers.microsoft.com/t5/PowerApps-Ideas/Form-validation-without-Submission/idc-p/303558#...).

 

For completeness, the final form to "Submit" all the previous partial forms would be achieved via patch, this could look something like the following:

 

If(
    !Form2.Valid,
// Then
    SubmitForm(Form2),
// Else
    Patch(
        '[dbo].[MyTable]',
        Defaults('[dbo].[MyTable]'),
        Form1.Updates,
        Form2.Updates
    );
    If(
        !IsEmpty(Errors('[dbo].[MyTable]')),
    // Then
        Notify(
            "Failed to submit, check your internet connection and try again.",
            NotificationType.Error
        ),
    // Else
        ResetForm(Form1);
        ResetForm(Form2);
        Navigate(Home);
        Notify(
            "Subitted new record.",
            NotificationType.Success
        );        
    );    
);
ToHe
Frequent Visitor

@richcoresln That is nifty! Complex issue solved with a simple fix! Thanks!

Anonymous
Not applicable

There is a 500 Control limit so there is a limit how big your single screen can be

Anonymous
Not applicable

If its low code no code this needs to be easy to do, otherwise simple Tasks are easier in Full Stack 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,442)