Showing posts with label Validation. Show all posts
Showing posts with label Validation. Show all posts

Sunday 12 May 2019

PowerApps Input Validation

Overview:  Validation can be handled in a multitude of ways in Power Apps, this technique I used for a fairly advanced set of Validation Requirements.


Basic Validation Example
To check that at least 1 of these two textInput box has been filled in.  Add this function to the DisplayMode:
If((IsBlank(srchMemberAccNo.Text)) && (IsBlank(srchMemberEmail.Text)), DisplayMode.Disabled, DisplayMode.Edit)

There are a number of ways to check if data exists in a control, I just try keep them consistent throughout my logic.  Here is a good approach: If(Not(IsBlank(txtBox1.Text)),<true>,<false>)

Saturday 27 November 2010

Error adding webpart containing validation control

Problem: When adding a custom built webpart with asp validator controls to a page, the user will encounter the following error when attempting to save the changes "Error: This page contains content or formatting that is not valid.".
Initial Hypothesis:
This error only happens when the webpart control has validators and prevents the user being able to add the webpart to the page.

Resolution: Disable the validator controls when editing the page.
Add the following public method in the server control code ...
public void EnableValidators(bool enableVal)
{
this.validatorName.Enabled = enableVal;
}
In the Webpart's CreateChildControls() procedure only add the user control/validation when not in edit mode
if (SPContext.Current.FormContext.FormMode == SPControlMode.Edit || SPContext.Current.FormContext.FormMode == SPControlMode.New)
{
//validator.enabled = false
((UserControl1)_ctl).EnableValidators(false);
}
else
{
//validator.enabled = false
((UserControl1)_ctl).EnableValidators(true);
}
}
Add the EnableValidators method to the user control code behind:
 
The validators will then be disabled when adding the web part​ to the page / editing the page, but still work in presentation mode.

Thanks to Paul W