In this blog, we will discover a new addition to the Client API. This event is the “OnOutputChange” that allows triggering a handler after a PCF control has notified the change of its outputs.
This event is valid for controls that live in model-driven app forms. The use of this event creates communication between PCF controls and the Client API. Using this event enables us to solve several problems, such as:
Now let’s see what methods the Client API offers to use this event:
(*) At the time of writing this blog, I believe that the current docs is not correct. We should use the getOutputs method instead of getOutput to get the output dictionary from the PCF.
We can summarize the communication flow between a Control PCF and the Client API with the following flow:
Enough about the theory. Let’s try to implement the following scenario. Let’s take the example of a PCF Control that validates the text input according to a regular expression:
We will apply this PCF control to the “telephone1” column of the account table, and attach the OnOutputChange event to this control. The idea is to display a notification on this control while the user is typing and the regular expression is not satisfied.
Before going to the Script implementation. You can download and read more details about the PCF Control used for this use case in my GitHub. Below is the configuration used for this scenario:
Now let see the JS part. Remember that we want to display the notification while the user is typing and not change the value of the column. For this we will use the OnOutputChange event and not the OnChange event:
Let’s focus on the extraction of the outputs. The method “getOutputs” returns a dictionary. According to my analysis, we need to use a specific key pattern to extract the value of the output “OutputName” for a control “ControlName”:
Key Pattern: {ControlName}.fieldControl.{OutputName}
Example: telephone1ControlOutput["telephone1.fieldControl.isValid"]
Finally, I share with you this tweet that discusses the same topic of this blog where the exchange is very instructive. Hope it helps …