1; (function (root, factory) { 2 const ns = root.FieldKit = root.FieldKit || {}; 3 ns.icons = ns.icons || {}; 4 factory(ns, root); 5})(window, function (ns, root) { 6 const { Field, FieldGroup } = ns; 7 8 /** 9 * Scan `root` for `[data-field]` elements and upgrade them to {@link Field}s. 10 * 11 * @param {ParentNode} root subtree to initialize 12 * @returns {void} 13 */ 14 function init(root = document) { 15 root.querySelectorAll('[data-field]').forEach(el => new Field(el)); 16 } 17 18 /** 19 * Bulk-apply validation messages. 20 * 21 * ``` 22 * // global 23 * setErrors({ email : 'Taken' }); 24 * 25 * // scoped to a specific form 26 * setErrors({ password: 'Wrong' }, formEl); 27 * ``` 28 * 29 * @param {Object} object 30 * @param {HTMLElement|string|null} scope Form, group or CSS selector 31 * @returns {void} 32 */ 33 function setErrors(object = {}, scope = null) { 34 if (scope) { 35 const host = typeof scope === 'string' 36 ? document.querySelector(scope) 37 : scope; 38 if (host) { 39 FieldGroup.get(host).setErrors(object); 40 } 41 } else { 42 // apply to every existing group (forms + data-field-group + body fallback) 43 document.querySelectorAll('form,[data-field-group], body').forEach(host => 44 FieldGroup.get(host).setErrors(object) 45 ); 46 } 47 } 48 49 // auto-init on DOM ready 50 document.addEventListener('DOMContentLoaded', () => { 51 if (!root.__FIELDKIT_READY) { 52 init(); 53 root.__FIELDKIT_READY = true; 54 } 55 }); 56 57 root.FieldKit = root.FieldKit || {}; 58 Object.assign(root.FieldKit, { init, setErrors }); 59 60 // namespace export 61 ns.init = init; 62 ns.setErrors = setErrors; 63});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.