onLayoutUpdate
Layout update handler
This example demonstrates how the onLayoutUpdate callback
sends a request using the Fetch API to update an existing layout. Once the request completes, the
result is returned to the widget through the
onResponse
callback.
Layout update handler
onLayoutUpdate = async function(layout: DIQ_Layout, onReponse: (result: DIQ_Result) => void) {
try {
const res = await fetch(`/api/layouts/${layout.key}`, {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(layout)
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
await res.json();
onResponse({ ok: true });
} catch (err) {
onResponse({
ok: false,
message: err.message || "Failed to update layout"
});
}
};