Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,40 @@ describe(
cy.get(".t--widget-textwidget").should("contain", "false");
_.deployMode.DeployApp();
});

it("Validate onCheckChange event is triggered on programmatic state change", function () {
cy.openPropertyPane("textwidget");
cy.updateCodeInput(".t--property-control-text", `{{checker.isChecked}}`);
_.agHelper.GetNAssertElementText(_.locators._textWidget, "false");

cy.openPropertyPane("checkboxwidget");
_.propPane.EnterJSContext(
"onCheckChange",
"{{showAlert('Checkbox state changed programmatically')}}",
);

cy.openPropertyPane("buttonwidget");
_.propPane.EnterJSContext(
"onClick",
"{{checker.setValue(!checker.isChecked)}}",
);

_.agHelper.ClickButton("Submit");
_.agHelper.ValidateToastMessage(
"Checkbox state changed programmatically",
);

_.agHelper.GetNAssertElementText(_.locators._textWidget, "true");

_.agHelper.ClickButton("Submit");
_.agHelper.ValidateToastMessage(
"Checkbox state changed programmatically",
);

_.agHelper.GetNAssertElementText(_.locators._textWidget, "false");

_.deployMode.DeployApp();
});
},
);

Expand Down
14 changes: 14 additions & 0 deletions app/client/src/widgets/CheckboxWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@ class CheckboxWidget extends BaseWidget<CheckboxWidgetProps, WidgetState> {
) {
this.props.updateWidgetMetaProperty("isDirty", false);
}

// Handle programmatic changes
if (
this.props.isChecked !== prevProps.isChecked &&
this.props.onCheckChange
) {
this.props.updateWidgetMetaProperty("isChecked", this.props.isChecked, {
triggerPropertyName: "onCheckChange",
dynamicString: this.props.onCheckChange,
event: {
type: EventType.ON_CHECK_CHANGE,
},
});
}
}

static getSetterConfig(): SetterConfig {
Expand Down
Loading