Page MenuHomeSealhub

table-add-button.stimulus.ts
No OneTemporary

Authored By
Unknown
Size
1019 B
Referenced Files
None
Subscribers
None

table-add-button.stimulus.ts

/// <reference lib="dom" />
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["textarea"];
defaultRowsNumber = 20;
addRow() {
const template = this.element
.closest("turbo-frame")
?.querySelector("template");
if (!template) {
throw new Error("Couldn't find template");
}
const tbody = this.element
.closest("turbo-frame")
?.querySelector("tbody");
if (!tbody) {
throw new Error("tbody not found");
}
const orig_template = template.innerHTML;
const placeholder = this.element.getAttribute("data-table-placeholder");
if (!placeholder) {
throw new Error("Could find placeholder attribute");
}
template.innerHTML = orig_template.replaceAll(
placeholder,
String(tbody.querySelectorAll("tr").length)
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
tbody.appendChild((template.cloneNode(true) as any).content);
template.innerHTML = orig_template;
}
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 17:16 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200194
Default Alt Text
table-add-button.stimulus.ts (1019 B)

Event Timeline