Thank you for visiting my site!

Home / PowerApps - Forms / Validation – custom form

Validation – custom form

If you start from a custom lists it will give you the basic form validation.

Removed al required fields from the List. – (form will submit empty).

0. On AppStart set the global variables

[code] Set(isFormValid, false);
Set(isTitleValid, false);
Set(isNumberValid, false);[/code]

1. In PowerApp selected data card and set required to true, (form will not submit until field is empty)

2. Set the error label to a variable:titleErrorMessage

3. set the error visibility to a variable: showTitleErrorMessage

4. Set the value of error label onChange of the input box. // This will take care of to show the error it will still submit form.

[code]If(
IsBlank(Title_Value.Text),
UpdateContext(
{
titleErrorMessage: "Error – Title cannot be empty.",
showTitleErrorMessage: true
}
);
Set(
isTitleValid,
false
),
UpdateContext(
{
titleErrorMessage: "",
showTitleErrorMessage: false
}
);
Set(
isTitleValid,
true
)
);
[/code]

5. For Number Values

[code] If(
Value(Number_Value.Text) < 100,
UpdateContext(
{
numberErrorMessage: "Error – Number must be greater than 100",
showNumberErrorMessage: true
}
);
Set(
isNumberValid,
false
),
Value(Number_Value.Text) > 1000,
UpdateContext(
{
numberErrorMessage: "Error – Number has to be less than 1000",
showNumberErrorMessage: true
}
);
Set(
isNumberValid,
false
),
UpdateContext(
{
numberErrorMessage: "",
showNumberErrorMessage: false
}
);
Set(
isNumberValid,
true
)
)
[/code]

To stop form from submitting add the following to the SharePointIntegration

OnSave:

[code]

If( isNumberValid && isNumberValid, Set(isFormValid,true), Set(isFormValid,false));

If(isFormValid,
Notify("Notification – Form can be submittid.",NotificationType.Error)//;ResetForm(frm),SubmitForm(frm)
);

If(!isFormValid,
Notify("Notification – Form cannot be submittid.",NotificationType.Error)//;ResetForm(frm),SubmitForm(frm)
)
[/code]

ADD YOUR COMMENT