@aurodesignsystem/auro-formkit 2.0.0-beta.17 → 2.0.0-beta.19
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/.turbo/cache/00aadf5485902e7b-meta.json +1 -0
- package/.turbo/cache/00aadf5485902e7b.tar.zst +0 -0
- package/.turbo/cache/036445b490c155bd-meta.json +1 -0
- package/.turbo/cache/036445b490c155bd.tar.zst +0 -0
- package/.turbo/cache/0447d55c21d0ac8f-meta.json +1 -0
- package/.turbo/cache/0447d55c21d0ac8f.tar.zst +0 -0
- package/.turbo/cache/2059bc724ac24519-meta.json +1 -1
- package/.turbo/cache/2059bc724ac24519.tar.zst +0 -0
- package/.turbo/cache/2397ce215c2442f0-meta.json +1 -0
- package/.turbo/cache/2397ce215c2442f0.tar.zst +0 -0
- package/.turbo/cache/23b3a2fea223679d-meta.json +1 -1
- package/.turbo/cache/23b3a2fea223679d.tar.zst +0 -0
- package/.turbo/cache/2c0d681132c153dd-meta.json +1 -1
- package/.turbo/cache/3795ae4e6361b8af-meta.json +1 -0
- package/.turbo/cache/3795ae4e6361b8af.tar.zst +0 -0
- package/.turbo/cache/3c39004da91359c5-meta.json +1 -0
- package/.turbo/cache/3c39004da91359c5.tar.zst +0 -0
- package/.turbo/cache/4006a206400d5c7b-meta.json +1 -1
- package/.turbo/cache/45cd32cd38eacbcb-meta.json +1 -1
- package/.turbo/cache/492dda333b8d15f1-meta.json +1 -1
- package/.turbo/cache/4ee009a370d54a8e-meta.json +1 -0
- package/.turbo/cache/4ee009a370d54a8e.tar.zst +0 -0
- package/.turbo/cache/50cd7dcfc9f820c5-meta.json +1 -1
- package/.turbo/cache/51eaa58d5c167de8-meta.json +1 -1
- package/.turbo/cache/5b57cc0e26e1fd5d-meta.json +1 -1
- package/.turbo/cache/60ad74320c682a2b-meta.json +1 -1
- package/.turbo/cache/61e218aba69cff58-meta.json +1 -1
- package/.turbo/cache/631d441eebe7e4ac-meta.json +1 -0
- package/.turbo/cache/631d441eebe7e4ac.tar.zst +0 -0
- package/.turbo/cache/64238eb3ce19a23b-meta.json +1 -0
- package/.turbo/cache/64238eb3ce19a23b.tar.zst +0 -0
- package/.turbo/cache/72c248aead46dc7a-meta.json +1 -0
- package/.turbo/cache/72c248aead46dc7a.tar.zst +0 -0
- package/.turbo/cache/77da375a012de9d0-meta.json +1 -1
- package/.turbo/cache/78418f9089673a21-meta.json +1 -1
- package/.turbo/cache/7964d1656e9e702a-meta.json +1 -1
- package/.turbo/cache/7bf2b06a479d0b30-meta.json +1 -1
- package/.turbo/cache/7c9ca6163e61285c-meta.json +1 -1
- package/.turbo/cache/80ebd4b1fa5c1e3a-meta.json +1 -0
- package/.turbo/cache/80ebd4b1fa5c1e3a.tar.zst +0 -0
- package/.turbo/cache/899d530990daf6ee-meta.json +1 -0
- package/.turbo/cache/899d530990daf6ee.tar.zst +0 -0
- package/.turbo/cache/8bb856bd31b5b479-meta.json +1 -1
- package/.turbo/cache/8f5fef3e04a6fcfa-meta.json +1 -1
- package/.turbo/cache/9d99fa3ab31d272f-meta.json +1 -0
- package/.turbo/cache/9d99fa3ab31d272f.tar.zst +0 -0
- package/.turbo/cache/a5df9f29608a70d3-meta.json +1 -0
- package/.turbo/cache/a5df9f29608a70d3.tar.zst +0 -0
- package/.turbo/cache/a779ea8b78ce9d59-meta.json +1 -1
- package/.turbo/cache/a9c36a3534c5496b-meta.json +1 -1
- package/.turbo/cache/abdfc2bec9f4fa6e-meta.json +1 -0
- package/.turbo/cache/abdfc2bec9f4fa6e.tar.zst +0 -0
- package/.turbo/cache/abe75d67a97447a5-meta.json +1 -0
- package/.turbo/cache/abe75d67a97447a5.tar.zst +0 -0
- package/.turbo/cache/ae04f51e4ebab64d-meta.json +1 -0
- package/.turbo/cache/ae04f51e4ebab64d.tar.zst +0 -0
- package/.turbo/cache/af7a63c49a499d50-meta.json +1 -0
- package/.turbo/cache/af7a63c49a499d50.tar.zst +0 -0
- package/.turbo/cache/b5e6dc7fb9ae1a2f-meta.json +1 -1
- package/.turbo/cache/b6a202cc85cb61a0-meta.json +1 -1
- package/.turbo/cache/ba270a0ef147f2e5-meta.json +1 -1
- package/.turbo/cache/be0b95293ea517cc-meta.json +1 -1
- package/.turbo/cache/c03a12ff38ba1e02-meta.json +1 -1
- package/.turbo/cache/c1312c6f8c051461-meta.json +1 -1
- package/.turbo/cache/c1312c6f8c051461.tar.zst +0 -0
- package/.turbo/cache/c3c8d8535ef6869a-meta.json +1 -0
- package/.turbo/cache/{56f2745125fdd552.tar.zst → c3c8d8535ef6869a.tar.zst} +0 -0
- package/.turbo/cache/c6c6411199b68170-meta.json +1 -1
- package/.turbo/cache/c6dbc49c3038946d-meta.json +1 -1
- package/.turbo/cache/cae7586c45bed13e-meta.json +1 -1
- package/.turbo/cache/cae7586c45bed13e.tar.zst +0 -0
- package/.turbo/cache/d007a96bfd17f5e4-meta.json +1 -0
- package/.turbo/cache/d007a96bfd17f5e4.tar.zst +0 -0
- package/.turbo/cache/d5db503b2eaf239c-meta.json +1 -1
- package/.turbo/cache/d775555355d6b8fc-meta.json +1 -1
- package/.turbo/cache/d7c3007be148d2a1-meta.json +1 -1
- package/.turbo/cache/db5e65d819bfe66b-meta.json +1 -1
- package/.turbo/cache/dc597b3ea4f61ec8-meta.json +1 -1
- package/.turbo/cache/e12c0f24d2d8f95b-meta.json +1 -0
- package/.turbo/cache/e12c0f24d2d8f95b.tar.zst +0 -0
- package/.turbo/cache/e1875aafbbfef851-meta.json +1 -0
- package/.turbo/cache/e1875aafbbfef851.tar.zst +0 -0
- package/.turbo/cache/e210e1ea5fb692c5-meta.json +1 -0
- package/.turbo/cache/e210e1ea5fb692c5.tar.zst +0 -0
- package/.turbo/cache/e62cfee068e3ef36-meta.json +1 -1
- package/.turbo/cache/e9abd65ee0250c1e-meta.json +1 -0
- package/.turbo/cache/e9abd65ee0250c1e.tar.zst +0 -0
- package/CHANGELOG.md +25 -0
- package/components/checkbox/.turbo/turbo-build.log +3 -3
- package/components/checkbox/.turbo/turbo-bundler.log +3 -3
- package/components/checkbox/README.md +1 -1
- package/components/checkbox/demo/api.md +4 -3
- package/components/checkbox/demo/api.min.js +11 -3
- package/components/checkbox/demo/index.min.js +11 -3
- package/components/checkbox/dist/auro-checkbox-group.d.ts +5 -0
- package/components/checkbox/dist/auro-checkbox-group.d.ts.map +1 -1
- package/components/checkbox/dist/index.js +11 -3
- package/components/checkbox/src/auro-checkbox-group.js +11 -3
- package/components/combobox/.turbo/turbo-build.log +3 -3
- package/components/combobox/README.md +4 -4
- package/components/combobox/demo/api.md +5 -4
- package/components/combobox/demo/api.min.js +16 -8
- package/components/combobox/demo/index.min.js +16 -8
- package/components/combobox/dist/auro-combobox.d.ts +5 -0
- package/components/combobox/dist/auro-combobox.d.ts.map +1 -1
- package/components/combobox/dist/index.js +16 -8
- package/components/combobox/src/auro-combobox.js +11 -3
- package/components/counter/.turbo/turbo-build.log +2 -2
- package/components/counter/.turbo/turbo-bundler.log +6 -3
- package/components/counter/README.md +1 -1
- package/components/counter/demo/api.md +11 -4
- package/components/counter/demo/api.min.js +20 -3
- package/components/counter/demo/index.min.js +20 -3
- package/components/counter/dist/auro-counter-group.d.ts +5 -0
- package/components/counter/dist/auro-counter-group.d.ts.map +1 -1
- package/components/counter/dist/auro-counter.d.ts +5 -0
- package/components/counter/dist/auro-counter.d.ts.map +1 -1
- package/components/counter/dist/index.js +20 -3
- package/components/counter/src/auro-counter-group.js +9 -1
- package/components/counter/src/auro-counter.js +11 -2
- package/components/datepicker/.turbo/turbo-build.log +3 -3
- package/components/datepicker/README.md +4 -4
- package/components/datepicker/demo/api.md +5 -4
- package/components/datepicker/demo/api.min.js +15 -7
- package/components/datepicker/demo/index.min.js +15 -7
- package/components/datepicker/dist/auro-datepicker.d.ts +5 -0
- package/components/datepicker/dist/auro-datepicker.d.ts.map +1 -1
- package/components/datepicker/dist/index.js +15 -7
- package/components/datepicker/src/auro-datepicker.js +10 -2
- package/components/dropdown/.turbo/turbo-build.log +3 -3
- package/components/dropdown/.turbo/turbo-bundler.log +3 -3
- package/components/dropdown/README.md +1 -1
- package/components/form/.turbo/turbo-build.log +3 -3
- package/components/form/.turbo/turbo-bundler.log +3 -3
- package/components/form/README.md +1 -1
- package/components/form/demo/api.min.js +218 -70
- package/components/form/demo/index.min.js +218 -70
- package/components/form/demo/registerDemoDeps.js +3 -2
- package/components/form/demo/working.html +23 -1
- package/components/form/dist/auro-form.d.ts +60 -6
- package/components/form/dist/auro-form.d.ts.map +1 -1
- package/components/form/dist/index.js +218 -70
- package/components/form/src/auro-form.js +216 -68
- package/components/form/src/styles/style-css.js +1 -1
- package/components/form/src/styles/style.css +0 -8
- package/components/form/src/styles/style.scss +0 -10
- package/components/input/.turbo/turbo-build.log +3 -3
- package/components/input/.turbo/turbo-bundler.log +3 -3
- package/components/input/README.md +1 -1
- package/components/input/demo/api.md +5 -5
- package/components/input/demo/api.min.js +5 -5
- package/components/input/demo/index.min.js +5 -5
- package/components/input/dist/base-input.d.ts +3 -3
- package/components/input/dist/base-input.d.ts.map +1 -1
- package/components/input/dist/index.js +5 -5
- package/components/input/src/base-input.js +5 -5
- package/components/menu/.turbo/turbo-build.log +3 -3
- package/components/menu/.turbo/turbo-bundler.log +3 -3
- package/components/menu/README.md +1 -1
- package/components/radio/.turbo/turbo-build.log +3 -3
- package/components/radio/.turbo/turbo-bundler.log +3 -3
- package/components/radio/README.md +1 -1
- package/components/radio/demo/api.md +4 -3
- package/components/radio/demo/api.min.js +9 -1
- package/components/radio/demo/index.min.js +9 -1
- package/components/radio/dist/auro-radio-group.d.ts +5 -0
- package/components/radio/dist/auro-radio-group.d.ts.map +1 -1
- package/components/radio/dist/index.js +9 -1
- package/components/radio/src/auro-radio-group.js +9 -1
- package/components/select/.turbo/turbo-build.log +3 -3
- package/components/select/README.md +3 -3
- package/components/select/demo/api.md +4 -3
- package/components/select/demo/api.min.js +9 -1
- package/components/select/demo/index.min.js +9 -1
- package/components/select/dist/auro-select.d.ts +5 -0
- package/components/select/dist/auro-select.d.ts.map +1 -1
- package/components/select/dist/index.js +9 -1
- package/components/select/src/auro-select.js +9 -1
- package/package.json +1 -1
- package/.turbo/cache/000950e13093845f-meta.json +0 -1
- package/.turbo/cache/000950e13093845f.tar.zst +0 -0
- package/.turbo/cache/02ee016619902665-meta.json +0 -1
- package/.turbo/cache/02ee016619902665.tar.zst +0 -0
- package/.turbo/cache/06ca4027e423c554-meta.json +0 -1
- package/.turbo/cache/06ca4027e423c554.tar.zst +0 -0
- package/.turbo/cache/1e855b2163b7c980-meta.json +0 -1
- package/.turbo/cache/1e855b2163b7c980.tar.zst +0 -0
- package/.turbo/cache/26dbf393768f87cc-meta.json +0 -1
- package/.turbo/cache/26dbf393768f87cc.tar.zst +0 -0
- package/.turbo/cache/31bd5687f46c7eba-meta.json +0 -1
- package/.turbo/cache/31bd5687f46c7eba.tar.zst +0 -0
- package/.turbo/cache/3488cff10dd06acd-meta.json +0 -1
- package/.turbo/cache/3488cff10dd06acd.tar.zst +0 -0
- package/.turbo/cache/3c8718d2ba6d3fe5-meta.json +0 -1
- package/.turbo/cache/3c8718d2ba6d3fe5.tar.zst +0 -0
- package/.turbo/cache/43693504bf6e7c4c-meta.json +0 -1
- package/.turbo/cache/43693504bf6e7c4c.tar.zst +0 -0
- package/.turbo/cache/56f2745125fdd552-meta.json +0 -1
- package/.turbo/cache/5f43911cbacf7df1-meta.json +0 -1
- package/.turbo/cache/5f43911cbacf7df1.tar.zst +0 -0
- package/.turbo/cache/647bda3b31d82dc2-meta.json +0 -1
- package/.turbo/cache/647bda3b31d82dc2.tar.zst +0 -0
- package/.turbo/cache/6951c2a52e5ab5f7-meta.json +0 -1
- package/.turbo/cache/6951c2a52e5ab5f7.tar.zst +0 -0
- package/.turbo/cache/876b8fa390c8ec81-meta.json +0 -1
- package/.turbo/cache/876b8fa390c8ec81.tar.zst +0 -0
- package/.turbo/cache/8f287fd5d33579ae-meta.json +0 -1
- package/.turbo/cache/8f287fd5d33579ae.tar.zst +0 -0
- package/.turbo/cache/8fcce3ba8357be57-meta.json +0 -1
- package/.turbo/cache/8fcce3ba8357be57.tar.zst +0 -0
- package/.turbo/cache/9b5868be65819fdf-meta.json +0 -1
- package/.turbo/cache/9b5868be65819fdf.tar.zst +0 -0
- package/.turbo/cache/a227e8174447e364-meta.json +0 -1
- package/.turbo/cache/a227e8174447e364.tar.zst +0 -0
- package/.turbo/cache/c3b2cc1b044a4135-meta.json +0 -1
- package/.turbo/cache/c3b2cc1b044a4135.tar.zst +0 -0
- package/.turbo/cache/cf143eb1a55684db-meta.json +0 -1
- package/.turbo/cache/cf143eb1a55684db.tar.zst +0 -0
- package/.turbo/cache/d5b85352bc667f19-meta.json +0 -1
- package/.turbo/cache/d5b85352bc667f19.tar.zst +0 -0
- package/.turbo/cache/e392fe0927e4af23-meta.json +0 -1
- package/.turbo/cache/e392fe0927e4af23.tar.zst +0 -0
- package/.turbo/cache/f2913bf19939d840-meta.json +0 -1
- package/.turbo/cache/f2913bf19939d840.tar.zst +0 -0
- package/.turbo/cache/f86b28e5ea2c66fe-meta.json +0 -1
- package/.turbo/cache/f86b28e5ea2c66fe.tar.zst +0 -0
|
@@ -24,7 +24,7 @@ const t=globalThis,i$1=t.trustedTypes,s=i$1?i$1.createPolicy("lit-html",{createH
|
|
|
24
24
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
25
25
|
*/class r extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=undefined;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const s=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=B(s,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return T}}r._$litElement$=true,r["finalized"]=true,globalThis.litElementHydrateSupport?.({LitElement:r});const i=globalThis.litElementPolyfillSupport;i?.({LitElement:r});(globalThis.litElementVersions??=[]).push("4.1.1");
|
|
26
26
|
|
|
27
|
-
var styleCss = i$3`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.testClass{display:inline-block;padding:var(--auro-text-body-size-default);border:1px solid var(--auro-color-border-error-on-light);color:var(--auro-color-border-error-on-light)}:focus-visible{background-color:var(--auro-color-border-error-on-light);color:var(--auro-color-base-white)}
|
|
27
|
+
var styleCss = i$3`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.testClass{display:inline-block;padding:var(--auro-text-body-size-default);border:1px solid var(--auro-color-border-error-on-light);color:var(--auro-color-border-error-on-light)}:focus-visible{background-color:var(--auro-color-border-error-on-light);color:var(--auro-color-base-white)}`;
|
|
28
28
|
|
|
29
29
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
30
30
|
// See LICENSE in the project root for license information.
|
|
@@ -96,7 +96,7 @@ class AuroLibraryRuntimeUtils {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/* eslint-disable no-underscore-dangle */
|
|
99
|
+
/* eslint-disable no-underscore-dangle,max-lines */
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
/**
|
|
@@ -124,7 +124,12 @@ class AuroLibraryRuntimeUtils {
|
|
|
124
124
|
class AuroForm extends r {
|
|
125
125
|
static get properties() {
|
|
126
126
|
return {
|
|
127
|
-
|
|
127
|
+
formState: { attribute: false },
|
|
128
|
+
_validity: { attribute: false },
|
|
129
|
+
_isInitialState: { attribute: false },
|
|
130
|
+
_elements: { attribute: false },
|
|
131
|
+
_submitElements: { attribute: false },
|
|
132
|
+
_resetElements: { attribute: false },
|
|
128
133
|
};
|
|
129
134
|
}
|
|
130
135
|
|
|
@@ -132,7 +137,24 @@ class AuroForm extends r {
|
|
|
132
137
|
super();
|
|
133
138
|
|
|
134
139
|
/** @type {FormState} */
|
|
135
|
-
this.
|
|
140
|
+
this.formState = {};
|
|
141
|
+
|
|
142
|
+
/** @type {"valid" | "invalid" | null} */
|
|
143
|
+
this._validity = null;
|
|
144
|
+
this._isInitialState = true;
|
|
145
|
+
|
|
146
|
+
/** @type {(HTMLElement & {reset: () => void})[]} */
|
|
147
|
+
this._elements = [];
|
|
148
|
+
|
|
149
|
+
/** @type {HTMLButtonElement[]} */
|
|
150
|
+
this._submitelements = [];
|
|
151
|
+
|
|
152
|
+
/** @type {HTMLButtonElement[]} */
|
|
153
|
+
this._resetElements = [];
|
|
154
|
+
|
|
155
|
+
// Bind listeners
|
|
156
|
+
this.reset = this.reset.bind(this);
|
|
157
|
+
this.submit = this.submit.bind(this);
|
|
136
158
|
}
|
|
137
159
|
|
|
138
160
|
// Note: button is NOT considered a form element in this context
|
|
@@ -166,7 +188,7 @@ class AuroForm extends r {
|
|
|
166
188
|
return this._isInElementCollection(AuroForm.formElementTags, element);
|
|
167
189
|
}
|
|
168
190
|
|
|
169
|
-
static get
|
|
191
|
+
static get buttonElementTags() {
|
|
170
192
|
return [
|
|
171
193
|
'button',
|
|
172
194
|
'auro-button',
|
|
@@ -174,12 +196,12 @@ class AuroForm extends r {
|
|
|
174
196
|
}
|
|
175
197
|
|
|
176
198
|
/**
|
|
177
|
-
* Check if the tag name is a
|
|
199
|
+
* Check if the tag name is a button element.
|
|
178
200
|
* @param {HTMLElement} element - The element to check.
|
|
179
201
|
* @returns {boolean}
|
|
180
202
|
*/
|
|
181
|
-
|
|
182
|
-
return this._isInElementCollection(AuroForm.
|
|
203
|
+
isButtonElement(element) {
|
|
204
|
+
return this._isInElementCollection(AuroForm.buttonElementTags, element);
|
|
183
205
|
}
|
|
184
206
|
|
|
185
207
|
static get styles() {
|
|
@@ -196,45 +218,76 @@ class AuroForm extends r {
|
|
|
196
218
|
* @returns {Record<string, string | number | boolean | string[] | null>} The form value.
|
|
197
219
|
*/
|
|
198
220
|
get value() {
|
|
199
|
-
return Object.keys(this.
|
|
200
|
-
acc[key] = this.
|
|
221
|
+
return Object.keys(this.formState).reduce((acc, key) => {
|
|
222
|
+
acc[key] = this.formState[key].value;
|
|
201
223
|
return acc;
|
|
202
224
|
}, {});
|
|
203
225
|
}
|
|
204
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Infer validity status based on current formState.
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
_calculateValidity() {
|
|
232
|
+
if (this.isInitialState) {
|
|
233
|
+
this._validity = null;
|
|
234
|
+
} else {
|
|
235
|
+
// go through validity states and return the first invalid state (if any)
|
|
236
|
+
const invalidKey = Object.keys(this.formState).
|
|
237
|
+
find((key) => {
|
|
238
|
+
const formKey = this.formState[key];
|
|
239
|
+
// these are NOT extra parens
|
|
240
|
+
// eslint-disable-next-line no-extra-parens
|
|
241
|
+
return (formKey.validity !== 'valid' && formKey.required) || (formKey.validity !== 'valid' && formKey.value !== null);
|
|
242
|
+
});
|
|
243
|
+
this._validity = invalidKey ? 'invalid' : 'valid';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Current validity state of the form, based on form element events.
|
|
249
|
+
* @returns {"valid" | "invalid"}
|
|
250
|
+
*/
|
|
205
251
|
get validity() {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// these are NOT extra :(
|
|
212
|
-
// eslint-disable-next-line no-extra-parens
|
|
213
|
-
return (formKey.validity !== 'valid' && formKey.required) || (formKey.validity !== 'valid' && formKey.value !== null);
|
|
214
|
-
});
|
|
252
|
+
return this._validity;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
_setInitialState() {
|
|
256
|
+
const anyTainted = Object.keys(this.formState).some((key) => this.formState[key].validity !== null || this.formState[key].value !== null);
|
|
215
257
|
|
|
216
|
-
|
|
258
|
+
this._isInitialState = !anyTainted;
|
|
259
|
+
|
|
260
|
+
this._resetElements.forEach((resetElement) => {
|
|
261
|
+
if (resetElement.hasAttribute("disabled")) {
|
|
262
|
+
resetElement.removeAttribute("disabled");
|
|
263
|
+
}
|
|
264
|
+
});
|
|
217
265
|
}
|
|
218
266
|
|
|
219
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Mostly internal way to determine if a form is in the initial state.
|
|
269
|
+
* @returns {boolean}
|
|
270
|
+
*/
|
|
220
271
|
get isInitialState() {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return !anyTainted;
|
|
272
|
+
return this._isInitialState;
|
|
224
273
|
}
|
|
225
274
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
275
|
+
setDisabledStateOnButtons() {
|
|
276
|
+
this._resetElements.forEach((element) => {
|
|
277
|
+
if (this.isInitialState) {
|
|
278
|
+
element.setAttribute("disabled", "");
|
|
279
|
+
} else {
|
|
280
|
+
element.removeAttribute("disabled");
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
this._submitelements.forEach((element) => {
|
|
285
|
+
if (this.isInitialState || this.validity !== "valid") {
|
|
286
|
+
element.setAttribute("disabled", "");
|
|
287
|
+
} else {
|
|
288
|
+
element.removeAttribute("disabled");
|
|
289
|
+
}
|
|
290
|
+
});
|
|
238
291
|
}
|
|
239
292
|
|
|
240
293
|
/**
|
|
@@ -242,16 +295,111 @@ class AuroForm extends r {
|
|
|
242
295
|
* @returns {NodeList}
|
|
243
296
|
*/
|
|
244
297
|
queryAuroElements() {
|
|
245
|
-
const
|
|
246
|
-
|
|
298
|
+
const queries = [
|
|
299
|
+
[
|
|
300
|
+
AuroForm.formElementTags,
|
|
301
|
+
'[name]'
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
AuroForm.buttonElementTags,
|
|
305
|
+
'[type=submit]'
|
|
306
|
+
],
|
|
307
|
+
[
|
|
308
|
+
AuroForm.buttonElementTags,
|
|
309
|
+
'[type=reset]'
|
|
310
|
+
]
|
|
311
|
+
];
|
|
247
312
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
313
|
+
return this.querySelectorAll(queries.flatMap(([
|
|
314
|
+
tags,
|
|
315
|
+
extraAttributes
|
|
316
|
+
]) => tags.map((tag) => `${tag}${extraAttributes}, [${tag}]${extraAttributes}`)).join(', '));
|
|
317
|
+
}
|
|
251
318
|
|
|
252
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Initialize (or reinitialize) the form state.
|
|
321
|
+
*/
|
|
322
|
+
initializeState() {
|
|
323
|
+
this.formState = {};
|
|
324
|
+
this._submitelements = [];
|
|
325
|
+
this._resetElements = [];
|
|
326
|
+
this._elements = [];
|
|
327
|
+
|
|
328
|
+
this.queryAuroElements().forEach((element) => {
|
|
329
|
+
if (this.isFormElement(element)) {
|
|
330
|
+
this.formState[element.getAttribute('name')] = {
|
|
331
|
+
value: element.getAttribute('value'),
|
|
332
|
+
validity: element.getAttribute('validity'),
|
|
333
|
+
required: element.hasAttribute('required'),
|
|
334
|
+
// element
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
this._elements.push(element);
|
|
338
|
+
}
|
|
253
339
|
|
|
254
|
-
|
|
340
|
+
if (this.isButtonElement(element) && element.getAttribute('type') === 'submit') {
|
|
341
|
+
element.removeEventListener('click', this.submit);
|
|
342
|
+
element.addEventListener('click', this.submit);
|
|
343
|
+
|
|
344
|
+
// Keep record of this element, so we can enable/disable as needed
|
|
345
|
+
this._submitelements.push(element);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (this.isButtonElement(element) && element.getAttribute('type') === 'reset') {
|
|
349
|
+
// Keep record of this element, so we can enable/disable as needed
|
|
350
|
+
element.removeEventListener('click', this.reset);
|
|
351
|
+
element.addEventListener('click', this.reset);
|
|
352
|
+
|
|
353
|
+
this._resetElements.push(element);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// Set enabled/disabled states on buttons
|
|
358
|
+
this.setDisabledStateOnButtons();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
reset() {
|
|
362
|
+
this._elements.forEach((element) => element.reset());
|
|
363
|
+
|
|
364
|
+
this.updateComplete.then(() => {
|
|
365
|
+
this.initializeState();
|
|
366
|
+
// Initial state must come first - validity can only be null if initial state is true
|
|
367
|
+
this._setInitialState();
|
|
368
|
+
this._calculateValidity();
|
|
369
|
+
|
|
370
|
+
// Wait for the above changes to run through, then disable submit/reset
|
|
371
|
+
this.updateComplete.then(() => {
|
|
372
|
+
this.setDisabledStateOnButtons();
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Submit fires an event called `submit` - just as you would expect from a normal form.
|
|
379
|
+
*
|
|
380
|
+
* @example ```
|
|
381
|
+
* const form = document.querySelector('auro-
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
submit() {
|
|
385
|
+
// Steps required to get out of beta:
|
|
386
|
+
// 1. Submit triggers a forced validation on ALL elements
|
|
387
|
+
// 2. Wait for validation to complete (this.updateComplete.then or similar)
|
|
388
|
+
// 3. If still valid, go ahead with submit.
|
|
389
|
+
this._elements.forEach((element) => {
|
|
390
|
+
if (element.tagName.toLowerCase() !== "auro-datepicker") {
|
|
391
|
+
// Next line currently does NOT force
|
|
392
|
+
element.validate();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
this.dispatchEvent(new CustomEvent('submit', {
|
|
397
|
+
bubbles: true,
|
|
398
|
+
composed: true,
|
|
399
|
+
detail: {
|
|
400
|
+
value: this.value
|
|
401
|
+
}
|
|
402
|
+
}));
|
|
255
403
|
}
|
|
256
404
|
|
|
257
405
|
/**
|
|
@@ -273,49 +421,49 @@ class AuroForm extends r {
|
|
|
273
421
|
|
|
274
422
|
// Update the form state when a form element is detected
|
|
275
423
|
slot.addEventListener('input', (event) => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (this.isFormElement(eventTarget)) {
|
|
280
|
-
this._formState[eventTarget.getAttribute("name")].value = eventTarget.value;
|
|
424
|
+
const targetName = event.target.getAttribute("name");
|
|
425
|
+
if (!this.isFormElement(event.target) || !targetName) {
|
|
426
|
+
return;
|
|
281
427
|
}
|
|
428
|
+
|
|
429
|
+
this.formState[targetName].value = event.target.value;
|
|
430
|
+
this.requestUpdate('formState');
|
|
282
431
|
});
|
|
283
432
|
|
|
284
433
|
slot.addEventListener('auroFormElement-validated', (event) => {
|
|
285
|
-
const
|
|
434
|
+
const targetName = event.target.getAttribute("name");
|
|
435
|
+
if (!this.isFormElement(event.target) || !targetName) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
286
438
|
|
|
287
|
-
this.
|
|
288
|
-
this.
|
|
439
|
+
this.formState[targetName].validity = event.detail.validity;
|
|
440
|
+
this._calculateValidity();
|
|
289
441
|
});
|
|
290
442
|
}
|
|
291
443
|
|
|
292
|
-
|
|
293
|
-
|
|
444
|
+
updated(_changedProperties) {
|
|
445
|
+
super.updated(_changedProperties);
|
|
294
446
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this._formState[element.getAttribute('name')] = {
|
|
298
|
-
value: element.getAttribute('value'),
|
|
299
|
-
validity: element.getAttribute('validity'),
|
|
300
|
-
required: element.hasAttribute('required'),
|
|
301
|
-
element
|
|
302
|
-
};
|
|
303
|
-
}
|
|
447
|
+
if (_changedProperties.has("formState")) {
|
|
448
|
+
this._setInitialState();
|
|
304
449
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
450
|
+
// Automatically infer disabled state now
|
|
451
|
+
this.setDisabledStateOnButtons();
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (_changedProperties.has("_validity")) {
|
|
455
|
+
this._setInitialState();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
onSlotChange() {
|
|
460
|
+
this.initializeState();
|
|
310
461
|
}
|
|
311
462
|
|
|
312
463
|
// function that renders the HTML and CSS into the scope of the component
|
|
313
464
|
render() {
|
|
314
465
|
return x`
|
|
315
466
|
<form>
|
|
316
|
-
<p>Value: ${JSON.stringify(this.value)}</p>
|
|
317
|
-
<p>Validity: ${this.validity}</p>
|
|
318
|
-
<h3>Auro form example</h3>
|
|
319
467
|
<slot @slotchange="${this.onSlotChange}"></slot>
|
|
320
468
|
</form>
|
|
321
469
|
`;
|