cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

PowerApps Component Framework

Hi Folks,

 

Quick question regarding PowerApps Component Framework. Is there a way to prevent save a parent form if there is any error occurred in PCF? 

 

The scenario I have is, my custom control generates random string as encryption key based on the input length provided in the configuration input. Since, its a key, space characters are not allowed hence, my control throws an error. However, that error is part of PCF life cycle and not been reported back to the form execution. Hence, the form is still allowed to save unless I inject a JS on form events. 

 

Any help is appreciated. 

 

Cheers

Jai

9 REPLIES 9
Highlighted
Community Support
Community Support

Re: PowerApps Component Framework

Hi @jhashwani ,

Do you want to prevent the custom PCF control from saving when there is an error occurred?

 

If you want to prevent the custom PCF control from saving when there is an error occurred, I afraid that there is no way to achieve your needs in PowerApps currently.

 

Currently, within PowerApps Component Framework, there is no function/context execution object to receive the error occurred within the PCF control.

 

If you would like this feature to be added in PowerApps, please submit an idea to PowerApps Ideas Forum:

https://powerusers.microsoft.com/t5/Power-Apps-Ideas/idb-p/PowerAppsIdeas

 

As an alternative solution, you could consider defined a JavaScript in your PCF code, then use the JS Code to validate if the entered characters are valid, if not, alert a error message.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Skilled Sharer
Skilled Sharer

Re: PowerApps Component Framework

Hi @jhashwani , 

 

Unfortunately you cannot control the form from inside the PCF, but maybe you can make use of required property of a field.

I'm thinking about setting the PCF field (where the PCF is registered) on the form as "Required", and inside your PCF - in getOutputs() - return  empty string as a value for your  parameter (as long the key is not valid). 

If the required field are not  filled in, the form should automatically stop the saving.

 

In case your attribute should be filled in only in some cases, and you cannot set it on required, you could work with a second bound parameter for your PCF, designed only for this purpose (a "valid" attribute, that's also required on the form).

 

I haven't tested this out, but maybe this can be an approach you can start with.

 

Best regards,

Diana

Highlighted
Impactful Individual
Impactful Individual

Re: PowerApps Component Framework

As Diana says the only way to handle it at the moment is to use a required field and return an empty value unless until you have the information you want.

 

I created an idea to solve this issue a year ago and it's still under review so if you want it fixed vote for it https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Allow-a-PCF-field-component-to-flag-a-field-as-...

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".
Highlighted
Impactful Individual
Impactful Individual

Re: PowerApps Component Framework

There is another solution as Benedick Bergmann blogged about earlier today which uses a two option field to check for validation

 

 https://benediktbergmann.eu/2020/05/01/pcf-prevent-saving-the-form-when-input-is-invalid/

 

It's still not an ideal solution though but it may be neater than making the text field a required field.

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".
Highlighted
Regular Visitor

Re: PowerApps Component Framework

Thanks everyone for your input. Looking at the current limitation In PCF, the best way to handle errors is using form JavaScript which is what I end up doing. 

One elegant way I found is, an

error can be thrown by the PCF on UI perhaps, we can prevent save form on save event and avoid any Control error notification for better usability. 

tough, having form execution context and notification access for a PCF field would be nice to have. That way, a solution would be intact at one place Instead of two.

 

cheers 

Jai

Highlighted
Community Support
Community Support

Re: PowerApps Component Framework

Hi @jhashwani ,

I agree with your though almost. Currently, as an available solution, I think JavaScript code could achieve your needs. You could set up JavaScript logic to validate the entered character.

 

If you want to display the error message within your PCF control, I think the openErrorDialog function under form context could achieve your needs:

context.navigation.openErrorDialog(options)

Please check the following article:

https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/navigation/opener...

 

Best regards, 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Skilled Sharer
Skilled Sharer

Re: PowerApps Component Framework

Hi @jhashwani ,

Making a required boolean bound to your pcf works. I've tried it out. https://dianabirkelbach.wordpress.com/2020/05/15/can-pcfs-communicate/.

And here the github with the tests: https://github.com/brasov2de/EvaluatePCFRequiredField

I've implemented that in a more generic way, but you don't necessarily need the postMessage, you can just define in the manifest another property linked to a required boolean attribute, which stops the form saving.

Best regards,

Diana

Highlighted
Impactful Individual
Impactful Individual

Re: PowerApps Component Framework

@DianaBirkelbach (sorry about this I'm actually replying to 2 of your comments at the moment with slight corrections and I feel guilty).

 

I've implemented that in a more generic way, but you don't necessarily need the postMessage, you can just define in the manifest another property linked to a boolean attribute (that is set on the form to be required) which stops the form saving.

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".
Highlighted
Skilled Sharer
Skilled Sharer

Re: PowerApps Component Framework

Don't worry @ben-thompson , 

Since my answer wasn't clear explained, your reply will help the others understand what I mean. Thank you for that.

I'm grateful being able to exchange ideas with you guys. To the other thread I'll come back soon. 🙂

Best regards,

Diana

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (9,114)