cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
VictorSotnikov
Helper II
Helper II

How to implement field validation in EdiForm?

I have an SQL DB. I have a Canvas App with a Gallery plus Edit Form that is bound to a table of the DB. Among others, there is a Text input in the Gallery that is bound to a column of the DB table.

I want to implement my own validation in Edit Form: to verify value in the Text input and, if it is invalid, to display a corresponding error message.

 

3 REPLIES 3
RandyHayes
Super User
Super User

@VictorSotnikov 

There are several ways to go about it.

 

First way - Integrate into the form logic. - This process is more logical if you have more than one field to validate.

The form has the Valid property that you can use to determine if it is valid.

In order to integrate with it, you make use of the Required property of the datacard and the Update property as well.  A form will be Valid as long as (among a couple of other things not related) the Update property of a Required datacard provides a value.

So, based on that, the simple process is this:

1) Create a label to display your error message (let's call it lblError)

2) Set the Visible property of the lblError to be your validation formula.  Ex.  IsMatch(yourTextInput.Text, Email) to validate an email address.

3) Set the Required property of the Datacard to: lblError.Visible

4) Set the Update property of the Datacard to: If(lblError.Visible, Blank(), yourTextInput.Text)

 

Now, the yourForm.Valid will be true if there is no error in validation and false if not.

ex: If(yourForm.Value, SubmitForm(yourForm))

 

 

 

Second way - Skip the integration

In this case you are not concerned about the .Valid property of the form as you may only have one validation.

So you would perform the above steps of creating the label and setting the visible property for the label.  Then you would skip steps 3 and 4 and revisit your submit formula and change to:

If(!lblError.Visible, SubmitForm(yourForm))

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

"...If(!lblError.Visible, SubmitForm(yourForm))..." - as I understand, this code should be put into OnSelect handler of a button that submits the form, correct?

RandyHayes
Super User
Super User

@VictorSotnikov 

Yes, both of the Submit formulas in the response would be in the OnSelect action of the button (depending on which method you use)

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

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 (4,047)