Skip to content

Instantly share code, notes, and snippets.

@andrew-grischenko
Last active July 27, 2023 15:15
Show Gist options
  • Save andrew-grischenko/bce9896ee736d4db699fea336bf10a11 to your computer and use it in GitHub Desktop.
Save andrew-grischenko/bce9896ee736d4db699fea336bf10a11 to your computer and use it in GitHub Desktop.
Power Apps PCF - Reset component
...
export class SomeComponent implements ComponentFramework.StandardControl<IInputs, IOutputs> {
private has_been_reset: boolean;
...
public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container:HTMLDivElement)
{
this.has_been_reset = false;
...
}
...
public updateView(context: ComponentFramework.Context<IInputs>): void
{
if(context.parameters.Reset.raw && !this.has_been_reset){
this.has_been_reset = true;
// do the clean up logic here
...
} else
// Technically, this will be done on ANY change of a property, which we don't care about as long as
// it's also done on setting of the Reset property
this.has_been_reset = false;
...
}
...
<?xml version="1.0" encoding="utf-8" ?>
<manifest>
<control ...>
<property name="Reset" display-name-key="Reset" description-key="Reset from start" of-type="TwoOptions" usage="input" required="false" default-value="false"/>
...
</control>
</manifest>
// Declare in a code (on screen visible or something like that) a dummy reset variable
Set(DummyResetVariable, false);
// Bind your control's Reset property to a dummy reset variable
// In the Component's inspector set value of the property Reset to
DummyResetVariable
// Now when you need to reset a control, set the dummy variable
Set(DummyResetVariable, true);
Set(DummyResetVariable, false);
@mitchellromanuik
Copy link

mitchellromanuik commented Jul 27, 2023

Hi Andrew,

default-value in manifest doesn't appear to load false when using the pcf watch

^^ updated. default-value is only support by model-driven and not canvasApp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment