Page MenuHomeSealhub

task-controller.ts
No OneTemporary

task-controller.ts

import { Controller } from "stimulus";
export default class TaskController extends Controller {
id: string;
connect() {
const dataIdAttr = this.element.getAttribute("data-id");
if (dataIdAttr) {
this.id = dataIdAttr;
}
}
async toggle(event: Event) {
const inputElement = event.target;
if (inputElement instanceof HTMLInputElement) {
const isChecked: boolean = inputElement.checked;
await fetch(`/api/v1/collections/tasks/${this.id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
done: isChecked,
}),
});
}
}
}

File Metadata

Mime Type
text/x-java
Expires
Thu, Jan 23, 23:00 (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
601002
Default Alt Text
task-controller.ts (621 B)

Event Timeline