Form Custom Form Error
This commit is contained in:
@@ -412,6 +412,16 @@ const formId = `f-${Math.random().toString(36).slice(2)}`;
|
|||||||
t.value = t.getAttribute("data-initial") || "";
|
t.value = t.getAttribute("data-initial") || "";
|
||||||
t.removeAttribute("data-initial");
|
t.removeAttribute("data-initial");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
form.addEventListener("wr:set-errors", (e) => {
|
||||||
|
const map = e.detail || {};
|
||||||
|
Object.entries(map).forEach(([name, message]) => {
|
||||||
|
const root = form.querySelector(
|
||||||
|
`[data-field="${CSS.escape(name)}"]`,
|
||||||
|
);
|
||||||
|
if (root) setError(root, message || "Invalid value");
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.readyState === "loading") {
|
if (document.readyState === "loading") {
|
||||||
|
|||||||
Reference in New Issue
Block a user