Add an id if the user forgot when using py-attribute (#1122)

This commit is contained in:
Fábio Rosado
2023-01-21 20:48:27 +00:00
committed by GitHub
parent 35de3aa154
commit 7947a8a2dc
3 changed files with 21 additions and 3 deletions

View File

@@ -156,10 +156,9 @@ export function initHandlers(interpreter: Interpreter) {
function createElementsWithEventListeners(interpreter: Interpreter, pyAttribute: string) {
const matches: NodeListOf<HTMLElement> = document.querySelectorAll(`[${pyAttribute}]`);
for (const el of matches) {
// If the element doesn't have an id, let's add one automatically!
if (el.id.length === 0) {
throw new TypeError(
`<${el.tagName.toLowerCase()}> must have an id attribute, when using the ${pyAttribute} attribute`,
);
ensureUniqueId(el);
}
const handlerCode = el.getAttribute(pyAttribute);
const event = pyAttributeToEvent.get(pyAttribute);