UNPKG

v-required

Version:

Componente Vue 3 para validação reativa de formulários, facilitando a criação de formulários dinâmicos e interativos com regras de validação personalizáveis.

75 lines (74 loc) 1.92 kB
function m(r, i) { for (const o in r) i[o] = r[o].map(([t, n]) => ({ message: t, condition: n() })); } function s(r, i) { for (const o in r) for (const t in r[o]) if (Array.isArray(i[o])) for (let n = 0; n < i[o].length; n++) i[o][n][t] = r[o][t].map( ([e, c]) => ({ message: e, condition: c(n) }) ); else { i[o] = []; for (let n = 0; n < r[o][t].length; n++) i[o][n] = {}, i[o][n][t] = r[o][t].map( ([e, c]) => ({ message: e, condition: c(n) }) ); } } const a = { // Verifica se a string é vazia ou nula isEmptyString(r) { return r == null || r.trim() === ""; } }, p = (r) => { if (r === void 0) throw new Error("validForm precisa de um parâmetro"); if (typeof r != "object") throw new Error("validForm precisa receber um objeto como parâmetro"); for (const i in r) { const o = r[i]; if (!o || o.length === 0) continue; const t = o[0]; if (t && "condition" in t && "message" in t) { const n = o; for (const e of n) if (e.condition) { const c = document.getElementById(`scroll_${i}`); return c && c.scrollIntoView({ behavior: "smooth", block: "center" }), !0; } } else { const n = o; for (let e = 0; e < n.length; e++) { const c = n[e]; if (c) for (const l in c) { const d = c[l]; if (d && d.some((f) => f.condition)) { const f = document.getElementById(`scroll_${i}_${l}_${e}`); return f && f.scrollIntoView({ behavior: "smooth", block: "center" }), !0; } } } } } return !1; }; export { m as senderErrors, s as senderErrorsDynamic, p as validForm, a as validate };