cancel
Showing results for 
Search instead for 
Did you mean: 

Allow a PCF field component to flag a field as invalid and stop page save.

Based on Use SetNotification to show error messages?  could I suggest that you make it possible for a powerapp component framework field component to flag it's value as invalid and stop the page from saving until the error is corrected 

 

I understand that this is currently possible using the clientapi but that requires additional work and a code (Javascript) or low code (Business rules) solution where this method would allow a zero code solution where the only thing required would be to add the field to the form, change the field type to the component and add the appropriate validation within the controls parameters / configuration.

Status: Under Review
Comments
Level 8

I forgot another reason for things being handled here.

 

By moving error handling within the component the out of the box language pack functionality can be used for translating error messages - something that is rarely implemented within Javascript scripts.

Level: Powered On

I support the idea. This will also open up the opporutnity to develop validator controls (like asp.net validator controls).

 

Ideally, we want

  1. A function implementation where we define validation logic and return a boolean value, and
  2. A property to set a custom error message

The implementation could be quite similar to Dynamics Portal client-side validation.

 

I understand this could be a fundamental change to the existing form validation and could be oustide of PCF development.

PowerApps Staff
Status changed to: Under Review
 
Level: Power Up

@ben-thompson@HemantG 

If the approach that I have used is a supported one, then for the setNotification/clearNotification functionality under PCF control, we can get the function for "setNotification" or "clearNotification" from "GetFunctionFromContextUtils" function (specified below) and process it.

By using the below approach, I have designed a PCF based Apply Regex Validation Custom Control https://github.com/rameelkhan/Apply-Regex-Validation which basically set/clear field notification.

 

public processForRegex(sValueToProcess: string): void
	{		
		var sNotification = this.isValid(this.sNotificationToUser) ?
			this.sNotificationToUser : this.sDefaultErrorLabel;
		var sUniqueId = sNotification + "_UniqueId";

		var objClearNotification = null;
		var objSetNotification = null;
		
		objClearNotification = this.GetFunctionFromContextUtils("clearNotification");
		objSetNotification = this.GetFunctionFromContextUtils("setNotification");		
		if(this.isValid(objClearNotification) && this.isValid(objSetNotification))
		{
			objClearNotification = objClearNotification as Function;
			objSetNotification = objSetNotification as Function;
			if(//logic for setNotification)
			{
				//setNotification(message,uniqueId)
				objSetNotification(sNotification, sUniqueId);
			}
			else //logic for clearNotification
			{
				//clearNotification(uniqueId)
				objClearNotification(sUniqueId);
			}
		}
	}
public GetFunctionFromContextUtils(sFunctionName: string): Function | null
	{
		var objFunctionToReturn = null;
		
		if(this.isValid(this.objContext) && this.isValid(this.objContext.utils) &&
		   this.isValid((this.objContext.utils as any)[sFunctionName]))
		{
			objFunctionToReturn = (this.objContext.utils as any)[sFunctionName] as Function;
		}
		
		return objFunctionToReturn;
	}