cancel
Showing results for 
Search instead for 
Did you mean: 

Much better support for Validation required - Add "OnValidate" and "Validatexxxxx" functions

(Apologies for the double post, the original post seems to have gone missing!)

 

Scenario: I have a PowerApp with a form that has a SharePoint document library as it's data source.  Because PowerApps doesn't support patching to a document library, I have instead added a button that invokes a Flow, so I can create/update an item in the document library myself (in this case, I'm creating a document set).

 

 

What I have to do now is have validation rules in both the "ErrorMessagex" labels that created automatically created by the data card, AND in the button's "OnSelect". 

 

For example, in the "Text" property of the ErrorMessage Label:

 

 

 If(IsBlank(ProjectNameValue.Text), "A project name must be provided")

 

 

And in the "OnSelect" of the button:

 

 

If (!IsBlank(ProjectNameValue.Text) 
    && !IsBlank(SomeDropDownValue.Selected.Value)
  , Set(FormValid, true), Set(FormValid, false));

If(FormValid,
    Set(FlowResponse, ProcessBusinessCaseRequest.Run(ProjectNameValue.Text, SomeDropDownValue.Selected.Value));
    If(!IsBlank(FlowResponse.docseturl), Navigate(Screen2, ScreenTransition.None)),
    Notify("Please correct the errors on the form.", NotificationType.Error)
)

 

 

There are two major drawbacks:

  • Here I am doubling up on validation rules.  While the example shown above would be for a simple form, for a large form with much more complex rules (e.g. where a field has more than one custom rule to apply), this becomes a nightmare from a maintenance point of view
  • When the user first opens the form, they are presented with validation errors in the "ErrorMessage" labels under each field.  Not great from a usability and presentation point of view - it would be best if they are presented ONLY when the user hits the button (provided there are any validation errors)

 

What would be much better:

The ability to have an "OnValidate" for controls, in tandem with a "ValidatonResult" function that can be returned from it.

 

So for instance, in the above scenario, "OnValidate" would look like this:

 

 

ValidationResult(!IsBlank(ProjectNameValue.Text), "A project name must be provided")

 

 

The syntax of the ValidationResult function would be something like this:

 

ValidationResult( Is Valid, [ Error Message ])

  • Is Valid - True/False that determines if the control is valid
  • Error Message - The validation error

 

Each control would also have a corresponding "ValidationMessage" property, which is only set when the "OnValidate" function is run against a control.  So in the case of the "ErrorMessage" labels that get created by a data card, their Text property gets set to:

 

 

ProjectNameValue.ValidationMessage

 

 

This means that the error message label is blank, until the corresponding "OnValidate" function is called on the "ProjectNameValue" control (provided of course "ValidationResult" returned "true" in the first parameter)

 

Forms and Screens should have an "OnValidate" function as well, so that validation can be performed at the form/screen level - so that combinations of control values (e.g. dependent controls) can be validated as well.

 

To trigger the "OnValidate" function, there are three functions that could be added:

 

  • ValidateControl( Control 1, [Control 2, ...] ) - validates only the controls nominated
  • ValidateFormForm ) - validates all controls (and the Form itself by calling "OnValidate" for the form)
  • ValidateScreenScreen ) - similar to ValidateForm, but for a screen.

 

The above three functions return true/false - meaning that "OnSelect" for the button in the example above now simply looks like this:

 

If (ValidateForm(Form1), Set(FormValid, true), Set(FormValid, false));

If(FormValid,
    Set(FlowResponse, ProcessBusinessCaseRequest.Run(ProjectNameValue.Text, SomeDropDownValue.Selected.Value));
    If(!IsBlank(FlowResponse.docseturl), Navigate(Screen2, ScreenTransition.None)),
    Notify("Please correct the errors on the form.", NotificationType.Error)
)

This removes the need to double up on validation rules in the button OnSelect, and means that we only have to change a validation rule in one spot.

 

 

Thanks!

Status: New
Comments
Level: Powered On

I have attempted to supply validation error messaging via the Notify() function, but this doesn't appear to be clearable when the application user clears the problem that caused the (error) message to be generated.

 

This is a nicely thought-out conceptual description, that appears to be to be a good fit to PowerApps' way of doing things.  How about this, Microsoft??

Level: Power Up

Coming from a previous Infopath / Nintex Forms environment, I find I cannot get my users to switch to PowerApps (much as I'd like to) without some easier to understand / implement validation rules and methods to apply them in place. 

 

For example we simply want to: 

1) Validate a field after someone's finished typing in it

2) Show a custom error message in a PowerApps form based on the input or contents of a field (dropdown, selector etc)

3) Validate on submit - in one place if possible rather than requiring separate validation applied on submission of a form OR on clicking of a submit button we've added. 

 

I don't understand why this is so complicated and convoluted. Online tutorials and technet articles are next to no help whatsoever.