From 57d1f91123d598b720030503412dd23fb6e38e51 Mon Sep 17 00:00:00 2001 From: frankpagan Date: Sun, 5 May 2024 14:14:10 -0500 Subject: [PATCH] fix: onEvent must liten at the document level, if no value allow comaparion of if esle conditions --- src/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 1a76f08..63f4423 100644 --- a/src/index.js +++ b/src/index.js @@ -233,10 +233,10 @@ const CoCreateEvents = { if (onEvent) { await new Promise((resolve, reject) => { const handleEvent = () => { - element.removeEventListener(onEvent, handleEvent); + document.removeEventListener(onEvent, handleEvent); resolve(); }; - element.addEventListener(onEvent, handleEvent); + document.addEventListener(onEvent, handleEvent); }); } @@ -250,7 +250,9 @@ const CoCreateEvents = { if (values) localStorage.setItem(key, values) } - if (!key || !values) + + // if (!key || !values) + if (!key) return } else { values = element.getAttribute(`${prefix}-value`) || element.getAttribute(`${prefix}-if-value`) || element.getAttribute(prefix); @@ -275,7 +277,7 @@ const CoCreateEvents = { let ifValue = element.getAttribute(`${prefix}-if-value`) if (!ifValue && ifValue !== "") - ifValue = await element.getValue() + ifValue = values // await element.getValue() else if (ifValue || ifValue === "") ifValue = [ifValue] else