I want to set read-only for a component in a UI builder client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2024 10:07 PM
I have added a Checkbox component and an Attachment component in the UI builder.
In the client script, I want to control the following, but it does not work.
【Action】
・Set Attachment's read-only setting to False when the checkbox is checked.
・When the checkbox is unchecked, set Attachment's read-only setting to True.
I created the following script, but nothing happened, so I would like to know if anyone has done something similar.
function handler({api, event, helpers, imports}) {
const isChecked = event.target.value;
const attachmentComponentId = 'attachment_1';
if (isChecked) {
api.updateComponent(attachmentComponentId, { readOnly: false });
} else {
api.updateComponent(attachmentComponentId, { readOnly: true });
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 06:36 AM
You can't directly manipulate a component from code. You'd want to create a boolean client state parameter and bind it to the isReadOnly property on the attachment component. Then your script can set the CSP to true or false and that will be reflected in the component.