voc-lib-js 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.mts CHANGED
@@ -36,8 +36,22 @@ type FormData = {
36
36
  id: string;
37
37
  code: string;
38
38
  form_name: string;
39
+ default_values?: Record<string, any>;
39
40
  fields: Field[];
40
41
  };
42
+ type SubmitConfig = {
43
+ api_endpoint?: string;
44
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
45
+ api_key?: string;
46
+ headers?: Record<string, string>;
47
+ body?: Record<string, any> | FormData;
48
+ contentType?: string | null;
49
+ credentials?: "omit" | "same-origin" | "include";
50
+ timeoutMs?: number;
51
+ signal?: AbortSignal;
52
+ responseType?: "json" | "text" | "blob" | "arrayBuffer";
53
+ retries?: number;
54
+ };
41
55
  interface RenderedForm {
42
56
  element: HTMLFormElement;
43
57
  validate: () => Array<{
@@ -51,6 +65,7 @@ declare function renderForm(element: string | HTMLElement, data: FormData, optio
51
65
  onSubmit?: (result: any, error?: any) => void;
52
66
  enableAutoSubmit?: boolean;
53
67
  style?: "bootstrap" | undefined | null;
68
+ submitConfig?: SubmitConfig;
54
69
  }): RenderedForm | null;
55
70
 
56
71
  declare const FormsLib: {
package/dist/main.d.ts CHANGED
@@ -36,8 +36,22 @@ type FormData = {
36
36
  id: string;
37
37
  code: string;
38
38
  form_name: string;
39
+ default_values?: Record<string, any>;
39
40
  fields: Field[];
40
41
  };
42
+ type SubmitConfig = {
43
+ api_endpoint?: string;
44
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
45
+ api_key?: string;
46
+ headers?: Record<string, string>;
47
+ body?: Record<string, any> | FormData;
48
+ contentType?: string | null;
49
+ credentials?: "omit" | "same-origin" | "include";
50
+ timeoutMs?: number;
51
+ signal?: AbortSignal;
52
+ responseType?: "json" | "text" | "blob" | "arrayBuffer";
53
+ retries?: number;
54
+ };
41
55
  interface RenderedForm {
42
56
  element: HTMLFormElement;
43
57
  validate: () => Array<{
@@ -51,6 +65,7 @@ declare function renderForm(element: string | HTMLElement, data: FormData, optio
51
65
  onSubmit?: (result: any, error?: any) => void;
52
66
  enableAutoSubmit?: boolean;
53
67
  style?: "bootstrap" | undefined | null;
68
+ submitConfig?: SubmitConfig;
54
69
  }): RenderedForm | null;
55
70
 
56
71
  declare const FormsLib: {
@@ -1 +1 @@
1
- "use strict";var VocLibJs=(()=>{var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(m,s)=>{for(var b in s)g(m,b,{get:s[b],enumerable:!0})},M=(m,s,b,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of F(s))!C.call(m,h)&&h!==b&&g(m,h,{get:()=>s[h],enumerable:!(i=w(s,h))||i.enumerable});return m};var q=m=>M(g({},"__esModule",{value:!0}),m);var D={};T(D,{FormsLib:()=>H,default:()=>N});function k(m,s=!0){let b=new FormData(m);if(s)return b;let i={};return b.forEach((h,d)=>{let r=(h instanceof File,h);Object.prototype.hasOwnProperty.call(i,d)?Array.isArray(i[d])?i[d].push(r):i[d]=[i[d],r]:i[d]=r}),i}function x(m,s,b){let i=[];if(typeof m=="string"?i=Array.from(document.querySelectorAll(m)):i=[m],i.length===0)return null;function h(){let r=b?.style==="bootstrap",p=document.createElement("form");p.classList.add("voc-form"),r&&p.classList.add("needs-validation"),p.id=s.id;let y=document.createElement("h2");y.textContent=s.form_name,p.appendChild(y);function f(e,a){a&&(a.min_length!==void 0&&(e.minLength=a.min_length),a.max_length!==void 0&&(e.maxLength=a.max_length),a.regex&&(e instanceof HTMLInputElement?e.pattern=a.regex:e.dataset.pattern=a.regex))}function L(e){if(!e.key&&!e.label)return null;let a=document.createElement("div");if(a.className="voc-form-group",r&&a.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),r&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),a.appendChild(t)}let u=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,c)=>{let l=document.createElement("label");l.classList.add("voc-form-checkbox-label"),r&&l.classList.add("form-check"),l.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(l.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),r&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.required&&(o.required=!0),e.default===n.value&&(o.checked=!0),l.appendChild(o),l.appendChild(document.createTextNode(n.label)),t.appendChild(l)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),r&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),r&&c.classList.add("form-check-input"),e.required&&(c.required=!0),e.default&&(c.checked=!!e.default),n.appendChild(c),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}u=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),r&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),f(t,e.validation),u=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),r&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let c=document.createElement("option");c.value=n.value,c.textContent=n.label,e.default===n.value&&(c.selected=!0),t.appendChild(c)}),e.width&&(t.style.width=e.width),u=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,c)=>{let l=document.createElement("label");l.classList.add("voc-form-radio-label"),r&&l.classList.add("form-check"),l.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(l.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),r&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.default===n.value&&(o.checked=!0),l.appendChild(o),l.appendChild(document.createTextNode(n.label)),t.appendChild(l)}),u=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),r&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),u=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),r&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),f(t,e.validation),u=t;break}}if(u&&a.appendChild(u),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,a.appendChild(t)}return a}s.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let a=document.createElement("div");if(a.className="voc-form-group voc-form-row",r&&a.classList.add("mb-3"),e.label){let t=document.createElement("h3");t.className="voc-form-row-label",t.textContent=e.label,a.appendChild(t)}if(e.description){let t=document.createElement("p");t.className="voc-form-row-description",t.textContent=e.description,a.appendChild(t)}let u=document.createElement("div");u.className="voc-form-row-items "+(e.direction||"horizontal"),a.appendChild(u),e.items.forEach(t=>{let n=L(t);n&&u.appendChild(n)}),p.appendChild(a)}else{let a=L(e);a&&p.appendChild(a)}});let v=document.createElement("button");return v.type="submit",v.className="voc-form-submit",v.textContent="Submit",r&&v.classList.add("btn","btn-primary"),p.appendChild(v),p}let d=h();return i[0].appendChild(d),{element:d,validate:()=>{let r=[];return d.querySelectorAll(":invalid").forEach(y=>{let f=y.validationMessage;r.push({element:y,message:f})}),r},getValues:()=>k(d),onSubmit:r=>{d.addEventListener("submit",p=>{p.preventDefault();let y=k(d);r(y,p)})}}}var E={renderForm:x};var H=E,N={FormsLib:E};return q(D);})();
1
+ "use strict";var VocLibJs=(()=>{var x=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var H=(p,c)=>{for(var h in c)x(p,h,{get:c[h],enumerable:!0})},q=(p,c,h,l)=>{if(c&&typeof c=="object"||typeof c=="function")for(let f of A(c))!M.call(p,f)&&f!==h&&x(p,f,{get:()=>c[f],enumerable:!(l=T(c,f))||l.enumerable});return p};var S=p=>q(x({},"__esModule",{value:!0}),p);var N={};H(N,{FormsLib:()=>_,default:()=>D});function L(p,c=!0){let h=new FormData(p);if(c)return h;let l={};return h.forEach((f,m)=>{let a=(f instanceof File,f);Object.prototype.hasOwnProperty.call(l,m)?Array.isArray(l[m])?l[m].push(a):l[m]=[l[m],a]:l[m]=a}),l}function C(p,c,h){let l=[];if(typeof p=="string"?l=Array.from(document.querySelectorAll(p)):l=[p],l.length===0)return null;function f(){let a=h?.style==="bootstrap",u=document.createElement("form");u.classList.add("voc-form"),a&&u.classList.add("needs-validation"),u.id=c.id;let v=document.createElement("h2");v.textContent=c.form_name,u.appendChild(v);function E(e,i){i&&(i.min_length!==void 0&&(e.minLength=i.min_length),i.max_length!==void 0&&(e.maxLength=i.max_length),i.regex&&(e instanceof HTMLInputElement?e.pattern=i.regex:e.dataset.pattern=i.regex))}function F(e){if(!e.key&&!e.label)return null;let i=c.default_values||{},g=e.name||e.key,r=g?i[g]:void 0,y=document.createElement("div");if(y.className="voc-form-group",a&&y.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),a&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),y.appendChild(t)}let b=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,s)=>{let d=document.createElement("label");d.classList.add("voc-form-checkbox-label"),a&&d.classList.add("form-check"),d.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(d.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${s}`),e.required&&(o.required=!0),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),d.appendChild(o),d.appendChild(document.createTextNode(n.label)),t.appendChild(d)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),a&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let s=document.createElement("input");s.type="checkbox",s.classList.add("voc-form-checkbox"),(e.key||e.name)&&(s.name=e.name||e.key,e.key&&(s.id=`voc-form-${e.key}`)),a&&s.classList.add("form-check-input"),e.required&&(s.required=!0),r!==void 0?s.checked=!!r:e.default&&(s.checked=!!e.default),n.appendChild(s),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}b=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),b=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),a&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let s=document.createElement("option");s.value=n.value,s.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(s.selected=!0):r!==void 0?r===n.value&&(s.selected=!0):e.default===n.value&&(s.selected=!0),t.appendChild(s)}),e.width&&(t.style.width=e.width),b=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,s)=>{let d=document.createElement("label");d.classList.add("voc-form-radio-label"),a&&d.classList.add("form-check"),d.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(d.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${s}`),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),d.appendChild(o),d.appendChild(document.createTextNode(n.label)),t.appendChild(d)}),b=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),a&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),b=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),b=t;break}}if(b&&y.appendChild(b),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,y.appendChild(t)}return y}c.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let i=document.createElement("div");if(i.className="voc-form-group voc-form-row",a&&i.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,i.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,i.appendChild(r)}let g=document.createElement("div");g.className="voc-form-row-items "+(e.direction||"horizontal"),i.appendChild(g),e.items.forEach(r=>{let y=F(r);y&&g.appendChild(y)}),u.appendChild(i)}else{let i=F(e);i&&u.appendChild(i)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",a&&k.classList.add("btn","btn-primary"),u.appendChild(k),u}let m=f();return l[0].appendChild(m),h&&h.submitConfig&&m.addEventListener("submit",a=>{a.preventDefault();let u=L(m);console.log(u)}),{element:m,validate:()=>{let a=[];return m.querySelectorAll(":invalid").forEach(v=>{let E=v.validationMessage;a.push({element:v,message:E})}),a},getValues:()=>L(m),onSubmit:a=>{m.addEventListener("submit",u=>{u.preventDefault();let v=L(m);a(v,u)})}}}var w={renderForm:C};var _=w,D={FormsLib:w};return S(N);})();
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(m,s)=>{for(var b in s)g(m,b,{get:s[b],enumerable:!0})},M=(m,s,b,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of F(s))!C.call(m,h)&&h!==b&&g(m,h,{get:()=>s[h],enumerable:!(i=w(s,h))||i.enumerable});return m};var q=m=>M(g({},"__esModule",{value:!0}),m);var D={};T(D,{FormsLib:()=>H,default:()=>N});module.exports=q(D);function k(m,s=!0){let b=new FormData(m);if(s)return b;let i={};return b.forEach((h,d)=>{let r=(h instanceof File,h);Object.prototype.hasOwnProperty.call(i,d)?Array.isArray(i[d])?i[d].push(r):i[d]=[i[d],r]:i[d]=r}),i}function x(m,s,b){let i=[];if(typeof m=="string"?i=Array.from(document.querySelectorAll(m)):i=[m],i.length===0)return null;function h(){let r=b?.style==="bootstrap",p=document.createElement("form");p.classList.add("voc-form"),r&&p.classList.add("needs-validation"),p.id=s.id;let y=document.createElement("h2");y.textContent=s.form_name,p.appendChild(y);function f(e,a){a&&(a.min_length!==void 0&&(e.minLength=a.min_length),a.max_length!==void 0&&(e.maxLength=a.max_length),a.regex&&(e instanceof HTMLInputElement?e.pattern=a.regex:e.dataset.pattern=a.regex))}function L(e){if(!e.key&&!e.label)return null;let a=document.createElement("div");if(a.className="voc-form-group",r&&a.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),r&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),a.appendChild(t)}let u=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,c)=>{let l=document.createElement("label");l.classList.add("voc-form-checkbox-label"),r&&l.classList.add("form-check"),l.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(l.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),r&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.required&&(o.required=!0),e.default===n.value&&(o.checked=!0),l.appendChild(o),l.appendChild(document.createTextNode(n.label)),t.appendChild(l)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),r&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),r&&c.classList.add("form-check-input"),e.required&&(c.required=!0),e.default&&(c.checked=!!e.default),n.appendChild(c),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}u=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),r&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),f(t,e.validation),u=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),r&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let c=document.createElement("option");c.value=n.value,c.textContent=n.label,e.default===n.value&&(c.selected=!0),t.appendChild(c)}),e.width&&(t.style.width=e.width),u=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,c)=>{let l=document.createElement("label");l.classList.add("voc-form-radio-label"),r&&l.classList.add("form-check"),l.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(l.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),r&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.default===n.value&&(o.checked=!0),l.appendChild(o),l.appendChild(document.createTextNode(n.label)),t.appendChild(l)}),u=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),r&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),u=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),r&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),f(t,e.validation),u=t;break}}if(u&&a.appendChild(u),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,a.appendChild(t)}return a}s.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let a=document.createElement("div");if(a.className="voc-form-group voc-form-row",r&&a.classList.add("mb-3"),e.label){let t=document.createElement("h3");t.className="voc-form-row-label",t.textContent=e.label,a.appendChild(t)}if(e.description){let t=document.createElement("p");t.className="voc-form-row-description",t.textContent=e.description,a.appendChild(t)}let u=document.createElement("div");u.className="voc-form-row-items "+(e.direction||"horizontal"),a.appendChild(u),e.items.forEach(t=>{let n=L(t);n&&u.appendChild(n)}),p.appendChild(a)}else{let a=L(e);a&&p.appendChild(a)}});let v=document.createElement("button");return v.type="submit",v.className="voc-form-submit",v.textContent="Submit",r&&v.classList.add("btn","btn-primary"),p.appendChild(v),p}let d=h();return i[0].appendChild(d),{element:d,validate:()=>{let r=[];return d.querySelectorAll(":invalid").forEach(y=>{let f=y.validationMessage;r.push({element:y,message:f})}),r},getValues:()=>k(d),onSubmit:r=>{d.addEventListener("submit",p=>{p.preventDefault();let y=k(d);r(y,p)})}}}var E={renderForm:x};var H=E,N={FormsLib:E};0&&(module.exports={FormsLib});
1
+ "use strict";var x=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var H=(p,c)=>{for(var h in c)x(p,h,{get:c[h],enumerable:!0})},q=(p,c,h,l)=>{if(c&&typeof c=="object"||typeof c=="function")for(let f of A(c))!M.call(p,f)&&f!==h&&x(p,f,{get:()=>c[f],enumerable:!(l=T(c,f))||l.enumerable});return p};var S=p=>q(x({},"__esModule",{value:!0}),p);var N={};H(N,{FormsLib:()=>_,default:()=>D});module.exports=S(N);function L(p,c=!0){let h=new FormData(p);if(c)return h;let l={};return h.forEach((f,m)=>{let a=(f instanceof File,f);Object.prototype.hasOwnProperty.call(l,m)?Array.isArray(l[m])?l[m].push(a):l[m]=[l[m],a]:l[m]=a}),l}function C(p,c,h){let l=[];if(typeof p=="string"?l=Array.from(document.querySelectorAll(p)):l=[p],l.length===0)return null;function f(){let a=h?.style==="bootstrap",u=document.createElement("form");u.classList.add("voc-form"),a&&u.classList.add("needs-validation"),u.id=c.id;let v=document.createElement("h2");v.textContent=c.form_name,u.appendChild(v);function E(e,i){i&&(i.min_length!==void 0&&(e.minLength=i.min_length),i.max_length!==void 0&&(e.maxLength=i.max_length),i.regex&&(e instanceof HTMLInputElement?e.pattern=i.regex:e.dataset.pattern=i.regex))}function F(e){if(!e.key&&!e.label)return null;let i=c.default_values||{},g=e.name||e.key,r=g?i[g]:void 0,y=document.createElement("div");if(y.className="voc-form-group",a&&y.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),a&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),y.appendChild(t)}let b=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,s)=>{let d=document.createElement("label");d.classList.add("voc-form-checkbox-label"),a&&d.classList.add("form-check"),d.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(d.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${s}`),e.required&&(o.required=!0),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),d.appendChild(o),d.appendChild(document.createTextNode(n.label)),t.appendChild(d)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),a&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let s=document.createElement("input");s.type="checkbox",s.classList.add("voc-form-checkbox"),(e.key||e.name)&&(s.name=e.name||e.key,e.key&&(s.id=`voc-form-${e.key}`)),a&&s.classList.add("form-check-input"),e.required&&(s.required=!0),r!==void 0?s.checked=!!r:e.default&&(s.checked=!!e.default),n.appendChild(s),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}b=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),b=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),a&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let s=document.createElement("option");s.value=n.value,s.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(s.selected=!0):r!==void 0?r===n.value&&(s.selected=!0):e.default===n.value&&(s.selected=!0),t.appendChild(s)}),e.width&&(t.style.width=e.width),b=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,s)=>{let d=document.createElement("label");d.classList.add("voc-form-radio-label"),a&&d.classList.add("form-check"),d.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(d.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${s}`),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),d.appendChild(o),d.appendChild(document.createTextNode(n.label)),t.appendChild(d)}),b=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),a&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),b=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),b=t;break}}if(b&&y.appendChild(b),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,y.appendChild(t)}return y}c.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let i=document.createElement("div");if(i.className="voc-form-group voc-form-row",a&&i.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,i.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,i.appendChild(r)}let g=document.createElement("div");g.className="voc-form-row-items "+(e.direction||"horizontal"),i.appendChild(g),e.items.forEach(r=>{let y=F(r);y&&g.appendChild(y)}),u.appendChild(i)}else{let i=F(e);i&&u.appendChild(i)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",a&&k.classList.add("btn","btn-primary"),u.appendChild(k),u}let m=f();return l[0].appendChild(m),h&&h.submitConfig&&m.addEventListener("submit",a=>{a.preventDefault();let u=L(m);console.log(u)}),{element:m,validate:()=>{let a=[];return m.querySelectorAll(":invalid").forEach(v=>{let E=v.validationMessage;a.push({element:v,message:E})}),a},getValues:()=>L(m),onSubmit:a=>{m.addEventListener("submit",u=>{u.preventDefault();let v=L(m);a(v,u)})}}}var w={renderForm:C};var _=w,D={FormsLib:w};0&&(module.exports={FormsLib});
package/dist/main.mjs CHANGED
@@ -1 +1 @@
1
- function g(u,h=!0){let v=new FormData(u);if(h)return v;let l={};return v.forEach((b,i)=>{let r=(b instanceof File,b);Object.prototype.hasOwnProperty.call(l,i)?Array.isArray(l[i])?l[i].push(r):l[i]=[l[i],r]:l[i]=r}),l}function L(u,h,v){let l=[];if(typeof u=="string"?l=Array.from(document.querySelectorAll(u)):l=[u],l.length===0)return null;function b(){let r=v?.style==="bootstrap",m=document.createElement("form");m.classList.add("voc-form"),r&&m.classList.add("needs-validation"),m.id=h.id;let p=document.createElement("h2");p.textContent=h.form_name,m.appendChild(p);function f(e,a){a&&(a.min_length!==void 0&&(e.minLength=a.min_length),a.max_length!==void 0&&(e.maxLength=a.max_length),a.regex&&(e instanceof HTMLInputElement?e.pattern=a.regex:e.dataset.pattern=a.regex))}function E(e){if(!e.key&&!e.label)return null;let a=document.createElement("div");if(a.className="voc-form-group",r&&a.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),r&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),a.appendChild(t)}let d=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,c)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),r&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),r&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.required&&(o.required=!0),e.default===n.value&&(o.checked=!0),s.appendChild(o),s.appendChild(document.createTextNode(n.label)),t.appendChild(s)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),r&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),r&&c.classList.add("form-check-input"),e.required&&(c.required=!0),e.default&&(c.checked=!!e.default),n.appendChild(c),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}d=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),r&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),f(t,e.validation),d=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),r&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let c=document.createElement("option");c.value=n.value,c.textContent=n.label,e.default===n.value&&(c.selected=!0),t.appendChild(c)}),e.width&&(t.style.width=e.width),d=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,c)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),r&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),r&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.default===n.value&&(o.checked=!0),s.appendChild(o),s.appendChild(document.createTextNode(n.label)),t.appendChild(s)}),d=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),r&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),d=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),r&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),f(t,e.validation),d=t;break}}if(d&&a.appendChild(d),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,a.appendChild(t)}return a}h.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let a=document.createElement("div");if(a.className="voc-form-group voc-form-row",r&&a.classList.add("mb-3"),e.label){let t=document.createElement("h3");t.className="voc-form-row-label",t.textContent=e.label,a.appendChild(t)}if(e.description){let t=document.createElement("p");t.className="voc-form-row-description",t.textContent=e.description,a.appendChild(t)}let d=document.createElement("div");d.className="voc-form-row-items "+(e.direction||"horizontal"),a.appendChild(d),e.items.forEach(t=>{let n=E(t);n&&d.appendChild(n)}),m.appendChild(a)}else{let a=E(e);a&&m.appendChild(a)}});let y=document.createElement("button");return y.type="submit",y.className="voc-form-submit",y.textContent="Submit",r&&y.classList.add("btn","btn-primary"),m.appendChild(y),m}let i=b();return l[0].appendChild(i),{element:i,validate:()=>{let r=[];return i.querySelectorAll(":invalid").forEach(p=>{let f=p.validationMessage;r.push({element:p,message:f})}),r},getValues:()=>g(i),onSubmit:r=>{i.addEventListener("submit",m=>{m.preventDefault();let p=g(i);r(p,m)})}}}var k={renderForm:L};var q=k,H={FormsLib:k};export{q as FormsLib,H as default};
1
+ function L(v,f=!0){let y=new FormData(v);if(f)return y;let d={};return y.forEach((g,c)=>{let a=(g instanceof File,g);Object.prototype.hasOwnProperty.call(d,c)?Array.isArray(d[c])?d[c].push(a):d[c]=[d[c],a]:d[c]=a}),d}function F(v,f,y){let d=[];if(typeof v=="string"?d=Array.from(document.querySelectorAll(v)):d=[v],d.length===0)return null;function g(){let a=y?.style==="bootstrap",m=document.createElement("form");m.classList.add("voc-form"),a&&m.classList.add("needs-validation"),m.id=f.id;let h=document.createElement("h2");h.textContent=f.form_name,m.appendChild(h);function E(e,i){i&&(i.min_length!==void 0&&(e.minLength=i.min_length),i.max_length!==void 0&&(e.maxLength=i.max_length),i.regex&&(e instanceof HTMLInputElement?e.pattern=i.regex:e.dataset.pattern=i.regex))}function w(e){if(!e.key&&!e.label)return null;let i=f.default_values||{},b=e.name||e.key,r=b?i[b]:void 0,u=document.createElement("div");if(u.className="voc-form-group",a&&u.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),a&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),u.appendChild(t)}let p=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,s)=>{let l=document.createElement("label");l.classList.add("voc-form-checkbox-label"),a&&l.classList.add("form-check"),l.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(l.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${s}`),e.required&&(o.required=!0),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),l.appendChild(o),l.appendChild(document.createTextNode(n.label)),t.appendChild(l)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),a&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let s=document.createElement("input");s.type="checkbox",s.classList.add("voc-form-checkbox"),(e.key||e.name)&&(s.name=e.name||e.key,e.key&&(s.id=`voc-form-${e.key}`)),a&&s.classList.add("form-check-input"),e.required&&(s.required=!0),r!==void 0?s.checked=!!r:e.default&&(s.checked=!!e.default),n.appendChild(s),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}p=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),p=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),a&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let s=document.createElement("option");s.value=n.value,s.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(s.selected=!0):r!==void 0?r===n.value&&(s.selected=!0):e.default===n.value&&(s.selected=!0),t.appendChild(s)}),e.width&&(t.style.width=e.width),p=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,s)=>{let l=document.createElement("label");l.classList.add("voc-form-radio-label"),a&&l.classList.add("form-check"),l.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(l.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${s}`),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),l.appendChild(o),l.appendChild(document.createTextNode(n.label)),t.appendChild(l)}),p=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),a&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),p=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),p=t;break}}if(p&&u.appendChild(p),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,u.appendChild(t)}return u}f.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let i=document.createElement("div");if(i.className="voc-form-group voc-form-row",a&&i.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,i.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,i.appendChild(r)}let b=document.createElement("div");b.className="voc-form-row-items "+(e.direction||"horizontal"),i.appendChild(b),e.items.forEach(r=>{let u=w(r);u&&b.appendChild(u)}),m.appendChild(i)}else{let i=w(e);i&&m.appendChild(i)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",a&&k.classList.add("btn","btn-primary"),m.appendChild(k),m}let c=g();return d[0].appendChild(c),y&&y.submitConfig&&c.addEventListener("submit",a=>{a.preventDefault();let m=L(c);console.log(m)}),{element:c,validate:()=>{let a=[];return c.querySelectorAll(":invalid").forEach(h=>{let E=h.validationMessage;a.push({element:h,message:E})}),a},getValues:()=>L(c),onSubmit:a=>{c.addEventListener("submit",m=>{m.preventDefault();let h=L(c);a(h,m)})}}}var x={renderForm:F};var S=x,_={FormsLib:x};export{S as FormsLib,_ as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voc-lib-js",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "A JavaScript library for VocPhone",
5
5
  "main": "./dist/main.cjs",
6
6
  "module": "./dist/main.mjs",