cancel
Showing results for 
Search instead for 
Did you mean: 

Form validation without Submission


I am creating a PowerApps that submits to a SharePoint list. We have lots of fields, so we've designed the app in multiple steps (like a wizard). But, we can't find a way to validate required fields at each step without submitting the entire form to SharePoint or checking each field individually. We've read many articles on form validation A few best practices in Data ValidationValidate function in PowerApps, etc. But, none of these seem to meet our simple needs. We basically want a simple way to validate the fields in a PowerApp form. For instance: if you have 5 fields marked as required in PowerApps, there should be something on the form to "validate" eveything based on the configuration in PowerApps. We were actually surprised this isn't there. So, if a simple form.Validate() already exists (without submitting the data to SharePoint), please let me know.

Status: New
Comments
Level: Powered On

I too need this for the same reason(s).. I can't imagine why it's not a feature or at least being worked on?!!

Level: Powered On

(Posting again here in case it helps someone else):

 

I also discovered this problem when trying to achieve something similar.

Quite surprised that this does not exist already.

However, having the following on a screens "Next" buttons "OnSelect" function seems to work:

 

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

If there is a cleaner way to achieve this I'd be interested in knowing what it is.

Level: Powered On

@richcoresln 

 

But you're submitting the form at this stage? That's why it's checking validation..?

 

We're wanting to go to another screen without submitting... When you get to the end and you want to submit you can only submit one of the multiple forms you will have this way??

Level: Powered On

But you're submitting the form at this stage? That's why it's checking validation..?

@beebulwe 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.

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 as suggested by @ggalipeau).

 


We're wanting to go to another screen without submitting... When you get to the end and you want to submit you can only submit one of the multiple forms you will have this way??

From my original answer, if the form is valid then we will Navigate to another screen (without submitting). If the subsequent screen is the "end" screen which you wish for the "Submit" to occur, this could be achieved using patch, like so:

 

If(
    !Form2.Valid,
// Then
    SubmitForm(Form2),
// Else
    Patch(
        '[dbo].[MyTable]',
        Defaults('[dbo].[MyTable]'),
        Form1.Updates,
        Form2.Updates
    );
// Do some more stuff, check for patch errors, reset forms, navigation, notifications etc... );

 

I hope this helps

Level: Powered On

@richcoresln 

 

Thanks that does help - oh and you are patching the forms together to submit - that is a great idea... I was saving the cross-screen forms values as variables and then submitting at the end.. (one form at the end populating the previous screens with variables to hidden cards). Very messy and hard to manage.


Do you have more of that code, it's really helpful (like the patch error, reset forms stuff!)


Cheers!

David

Level: Powered On

@beebulyes patching the forms saves having to deal with copying individual form property values.

 

Here you go:

 

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
        );        
    );    
);
Level: Powered On

Thanks @richcoresln that's incredible helpful, as I mentioned I was saving each screen into global variables and doing manual validation so this will help on my next project!

 

Cheers Cat Very Happy

David

Level: Powered On

@richcoresln do you have the code for your first screen also? How do you navigate, is there anything funky you have to do on the first page for the form1 values to still be available?

 

Thanks

David

Level: Powered On

@beebul  not particularly, the navigation button to open the first screen in the wizard would have something like the following in the OnSelected event:

 

NewForm(Form1); NewForm(Form2); Navigate(CustomFormScreen1);