Question:
I’m facing an issue with a list type property where I store some default list items created with a custom type (Refer to the screenshots). When I’m trying to access(Read or Write) that list type property called itemsVisibilityList through the wix-widget API inside my panel code, it gives me an error. ( Specially in wixWidget.setProps() method). I couldn’t even build a test version to check if it’s working in editor.
Error I’m getting in line ‘await wixWidget.setProps({ itemsVisibilityList: visibilityList })’: Argument of type ‘{ itemsVisibilityList: any; }’ is not assignable to parameter of type ‘Partial<WidgetProps>’. Object literal may only specify known properties, and ‘itemsVisibilityList’ does not exist in type ‘Partial<WidgetProps>’.
I would like to know what I’m doing wrong here and how to work with a list type widget property specially accessing it through the wixWIdget.getProps() and updating it with wixWidget.setProps().
Product:
Wix Blocks
What are you trying to achieve:
I need to update the default items’ values inside the itemsVisibilityList according to the current state of the toggle switch element in the custom panel
What have you already tried:
I’ve followed the velo Widget API documentation where I couldn’t find any solution.
Wix Blocks: Creating and Managing List Type Properties in Widget API
Code Snippet
async function setToggleSwitches() {
try {
const props = await wixWidget.getProps();
const visibilityList = props['itemsVisibilityList'];
if (visibilityList) {
for (const itemVisibility of visibilityList) {
const switchID = `#${itemVisibility["itemName"]}Switch`;
const itemNo = parseInt(itemVisibility["itemNo"]);
$w(switchID).onChange(async (event) => {
visibilityList[itemNo].isEnabled = event.target.checked;
await wixWidget.setProps({ itemsVisibilityList: visibilityList });
});
}
}
} catch (error) {
console.error("~ Catched Error ~ [Fn setToggleSwitches] - set-props.js", error.message);
}
}
Screeshots