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.
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.
"...If(!lblError.Visible, SubmitForm(yourForm))..." - as I understand, this code should be put into OnSelect handler of a button that submits the form, correct?
Yes, both of the Submit formulas in the response would be in the OnSelect action of the button (depending on which method you use)
User | Count |
---|---|
118 | |
86 | |
83 | |
74 | |
69 |
User | Count |
---|---|
214 | |
179 | |
141 | |
109 | |
83 |