@aurodesignsystem/auro-formkit 2.0.0-beta.32 → 2.0.0-beta.33
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/02882630667e46f8-meta.json +1 -1
- package/.turbo/cache/02882630667e46f8.tar.zst +0 -0
- package/.turbo/cache/0899fc2ef909db30-meta.json +1 -1
- package/.turbo/cache/0899fc2ef909db30.tar.zst +0 -0
- package/.turbo/cache/1d4280429ff4222f-meta.json +1 -1
- package/.turbo/cache/1e094164b4932553-meta.json +1 -1
- package/.turbo/cache/1e3f844e58a3d4f2-meta.json +1 -1
- package/.turbo/cache/1e3f844e58a3d4f2.tar.zst +0 -0
- package/.turbo/cache/251ba344c6338ba3-meta.json +1 -1
- package/.turbo/cache/28fe2121c9ba81e2-meta.json +1 -1
- package/.turbo/cache/298b6ff0272e6226-meta.json +1 -1
- package/.turbo/cache/2abb5400a01a1694-meta.json +1 -1
- package/.turbo/cache/30fda91ef83677e4-meta.json +1 -1
- package/.turbo/cache/317b33937a355f80-meta.json +1 -0
- package/.turbo/cache/317b33937a355f80.tar.zst +0 -0
- package/.turbo/cache/3221d91a94756c26-meta.json +1 -1
- package/.turbo/cache/3ab09fe7cf32b3bf-meta.json +1 -1
- package/.turbo/cache/3c795c4f80600a07-meta.json +1 -0
- package/.turbo/cache/3c795c4f80600a07.tar.zst +0 -0
- package/.turbo/cache/3f1b3db13386acdc-meta.json +1 -1
- package/.turbo/cache/430c124614841675-meta.json +1 -1
- package/.turbo/cache/45bdeb0396723b25-meta.json +1 -1
- package/.turbo/cache/4e8248fc9e1e3e8f-meta.json +1 -1
- package/.turbo/cache/4e8248fc9e1e3e8f.tar.zst +0 -0
- package/.turbo/cache/4e9c9a5dd62c50a4-meta.json +1 -1
- package/.turbo/cache/5326b73ddda05291-meta.json +1 -1
- package/.turbo/cache/5fc9a7a072827b7b-meta.json +1 -1
- package/.turbo/cache/62214e9883afcc4d-meta.json +1 -1
- package/.turbo/cache/6e0b3da6e3ff3718-meta.json +1 -1
- package/.turbo/cache/721262daa6b8164a-meta.json +1 -1
- package/.turbo/cache/721262daa6b8164a.tar.zst +0 -0
- package/.turbo/cache/753b119a389426be-meta.json +1 -1
- package/.turbo/cache/7593109ea54e7505-meta.json +1 -1
- package/.turbo/cache/7629bef0037115af-meta.json +1 -1
- package/.turbo/cache/76667a5d27a45c7a-meta.json +1 -1
- package/.turbo/cache/76667a5d27a45c7a.tar.zst +0 -0
- package/.turbo/cache/785960dbbde053b6-meta.json +1 -1
- package/.turbo/cache/92b4b6ba93458685-meta.json +1 -1
- package/.turbo/cache/9c15f2276d1905d6-meta.json +1 -1
- package/.turbo/cache/9c15f2276d1905d6.tar.zst +0 -0
- package/.turbo/cache/a263932c5b42ec4f-meta.json +1 -1
- package/.turbo/cache/a263932c5b42ec4f.tar.zst +0 -0
- package/.turbo/cache/b10915c26145587e-meta.json +1 -1
- package/.turbo/cache/b10915c26145587e.tar.zst +0 -0
- package/.turbo/cache/b169402fda42f218-meta.json +1 -1
- package/.turbo/cache/b169402fda42f218.tar.zst +0 -0
- package/.turbo/cache/b32a99cd28bc1388-meta.json +1 -0
- package/.turbo/cache/b32a99cd28bc1388.tar.zst +0 -0
- package/.turbo/cache/bed01678759af66e-meta.json +1 -1
- package/.turbo/cache/bed01678759af66e.tar.zst +0 -0
- package/.turbo/cache/bf154f26b6bb6f24-meta.json +1 -1
- package/.turbo/cache/bf154f26b6bb6f24.tar.zst +0 -0
- package/.turbo/cache/bf3d1eace5e676f9-meta.json +1 -1
- package/.turbo/cache/c103542625831d7c-meta.json +1 -1
- package/.turbo/cache/c103542625831d7c.tar.zst +0 -0
- package/.turbo/cache/c860cecd25be20af-meta.json +1 -1
- package/.turbo/cache/ca9625ba0a5cd272-meta.json +1 -1
- package/.turbo/cache/cbcd9db8ac9a2d52-meta.json +1 -1
- package/.turbo/cache/d3afdb9a7db9eacc-meta.json +1 -1
- package/.turbo/cache/d8ecdff9c663c38e-meta.json +1 -1
- package/.turbo/cache/de494df6a3006101-meta.json +1 -1
- package/.turbo/cache/e56a9865641ec3e8-meta.json +1 -1
- package/.turbo/cache/e7ed9e7056d80938-meta.json +1 -1
- package/.turbo/cache/e837827cd24834c4-meta.json +1 -1
- package/.turbo/cache/e9ff93179777aa26-meta.json +1 -1
- package/.turbo/cache/ed455be2856be7ac-meta.json +1 -1
- package/.turbo/cache/f2e689c8cdd1aafe-meta.json +1 -1
- package/.turbo/cache/f473f3d9902768db-meta.json +1 -1
- package/.turbo/cache/f7ab9a13f9acc0ab-meta.json +1 -1
- package/.turbo/cache/f93a33e9c99af8e4-meta.json +1 -0
- package/.turbo/cache/f93a33e9c99af8e4.tar.zst +0 -0
- package/.turbo/cache/ff3c8a3042cab66e-meta.json +1 -1
- package/CHANGELOG.md +13 -0
- package/components/checkbox/.turbo/turbo-build.log +3 -3
- package/components/checkbox/README.md +1 -1
- package/components/combobox/.turbo/turbo-build.log +1 -1
- package/components/combobox/README.md +4 -4
- package/components/counter/.turbo/turbo-build.log +2 -2
- package/components/counter/.turbo/turbo-bundler.log +3 -3
- package/components/counter/README.md +1 -1
- package/components/datepicker/.turbo/turbo-build.log +3 -3
- package/components/datepicker/README.md +4 -4
- package/components/dropdown/.turbo/turbo-build.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 +75 -33
- package/components/form/demo/index.min.js +75 -33
- package/components/form/demo/registerDemoDeps.js +13 -0
- package/components/form/dist/auro-form.d.ts +18 -0
- package/components/form/dist/auro-form.d.ts.map +1 -1
- package/components/form/dist/index.js +75 -33
- package/components/form/src/auro-form.js +75 -33
- package/components/helptext/.turbo/turbo-build.log +1 -1
- package/components/helptext/.turbo/turbo-bundler.log +1 -1
- package/components/input/.turbo/turbo-build.log +3 -3
- package/components/input/README.md +1 -1
- 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/README.md +1 -1
- package/components/select/.turbo/turbo-build.log +3 -3
- package/components/select/README.md +3 -3
- package/package.json +1 -1
- package/.turbo/cache/62e73e98c9b176ea-meta.json +0 -1
- package/.turbo/cache/62e73e98c9b176ea.tar.zst +0 -0
- package/.turbo/cache/91c75fdf2c775926-meta.json +0 -1
- package/.turbo/cache/91c75fdf2c775926.tar.zst +0 -0
- package/.turbo/cache/b1f20257439cbded-meta.json +0 -1
- package/.turbo/cache/b1f20257439cbded.tar.zst +0 -0
- package/.turbo/cache/e14312dd3d4148f7-meta.json +0 -1
- package/.turbo/cache/e14312dd3d4148f7.tar.zst +0 -0
|
@@ -155,6 +155,8 @@ class AuroForm extends r {
|
|
|
155
155
|
// Bind listeners
|
|
156
156
|
this.reset = this.reset.bind(this);
|
|
157
157
|
this.submit = this.submit.bind(this);
|
|
158
|
+
this.sharedInputListener = this.sharedInputListener.bind(this);
|
|
159
|
+
this.sharedValidationListener = this.sharedValidationListener.bind(this);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
// Note: button is NOT considered a form element in this context
|
|
@@ -164,7 +166,12 @@ class AuroForm extends r {
|
|
|
164
166
|
'auro-input',
|
|
165
167
|
'auro-select',
|
|
166
168
|
'auro-datepicker',
|
|
169
|
+
'auro-combobox',
|
|
170
|
+
// checkbox and radio are grouped elements
|
|
167
171
|
'auro-checkbox-group',
|
|
172
|
+
'auro-radio-group',
|
|
173
|
+
// while counter is groupable, the group is for min/max values and not for grouped values
|
|
174
|
+
'auro-counter-group'
|
|
168
175
|
];
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -199,6 +206,18 @@ class AuroForm extends r {
|
|
|
199
206
|
return this._isInElementCollection(AuroForm.formElementTags, element);
|
|
200
207
|
}
|
|
201
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Validates if an event is from a valid form element with a name.
|
|
211
|
+
* @param {Event} event - The event to validate.
|
|
212
|
+
* @returns {boolean} - True if event is valid for processing.
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
_eventIsValidFormEvent(event) {
|
|
216
|
+
const targetName = event.target.getAttribute("name");
|
|
217
|
+
return this.isFormElement(event.target) && targetName;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
202
221
|
static get buttonElementTags() {
|
|
203
222
|
return [
|
|
204
223
|
'button',
|
|
@@ -358,7 +377,7 @@ class AuroForm extends r {
|
|
|
358
377
|
}
|
|
359
378
|
|
|
360
379
|
this.formState[targetName] = {
|
|
361
|
-
value: element.getAttribute('value'),
|
|
380
|
+
value: element.value || element.getAttribute('value'),
|
|
362
381
|
validity: element.validity || null,
|
|
363
382
|
required: element.hasAttribute('required'),
|
|
364
383
|
// element
|
|
@@ -466,48 +485,69 @@ class AuroForm extends r {
|
|
|
466
485
|
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroForm);
|
|
467
486
|
}
|
|
468
487
|
|
|
469
|
-
|
|
470
|
-
|
|
488
|
+
/**
|
|
489
|
+
* Shared input listener for all form elements.
|
|
490
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
491
|
+
*/
|
|
492
|
+
sharedInputListener(event) {
|
|
493
|
+
const targetName = event.target.getAttribute("name");
|
|
471
494
|
|
|
472
|
-
|
|
495
|
+
// This should only happen if some bubble-up event is fired from inside a form element.
|
|
496
|
+
if (!this._eventIsValidFormEvent(event)) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
473
499
|
|
|
474
|
-
//
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
500
|
+
// Occasionally, a form element will emit their event before the form can read data about the form element.
|
|
501
|
+
if (!this.formState[targetName] && this.isFormElement(event.target)) {
|
|
502
|
+
this._addElementToState(event.target);
|
|
503
|
+
}
|
|
480
504
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
505
|
+
// Check special input types and handle their edge cases
|
|
506
|
+
if (this._isElementTag('auro-datepicker', event.target) && event.target.hasAttribute('range')) {
|
|
507
|
+
this.formState[targetName].value = event.target.values;
|
|
508
|
+
this.requestUpdate('formState');
|
|
509
|
+
} else {
|
|
510
|
+
this.formState[targetName].value = event.target.value;
|
|
511
|
+
this.requestUpdate('formState');
|
|
512
|
+
}
|
|
513
|
+
}
|
|
485
514
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
515
|
+
/**
|
|
516
|
+
* Shared validation listener for all form elements.
|
|
517
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
518
|
+
*/
|
|
519
|
+
sharedValidationListener(event) {
|
|
520
|
+
const targetName = event.target.getAttribute("name");
|
|
521
|
+
if (!this._eventIsValidFormEvent(event)) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
495
524
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
525
|
+
if (!this.formState[targetName]) {
|
|
526
|
+
this._addElementToState(event.target);
|
|
527
|
+
}
|
|
501
528
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
529
|
+
this.formState[targetName].validity = event.detail.validity;
|
|
530
|
+
this._calculateValidity();
|
|
531
|
+
}
|
|
505
532
|
|
|
506
|
-
|
|
507
|
-
|
|
533
|
+
_attachEventListeners() {
|
|
534
|
+
this.queryAuroElements().forEach((element) => {
|
|
535
|
+
// remove any existing event listeners (in case of re-initialization)
|
|
536
|
+
element.removeEventListener('input', this.sharedInputListener);
|
|
537
|
+
element.removeEventListener('auroFormElement-validated', this.sharedValidationListener);
|
|
538
|
+
|
|
539
|
+
// add new event listeners
|
|
540
|
+
element.addEventListener('input', this.sharedInputListener);
|
|
541
|
+
element.addEventListener('auroFormElement-validated', this.sharedValidationListener);
|
|
508
542
|
});
|
|
509
543
|
}
|
|
510
544
|
|
|
545
|
+
firstUpdated(_changedProperties) {
|
|
546
|
+
super.firstUpdated(_changedProperties);
|
|
547
|
+
|
|
548
|
+
this._attachEventListeners();
|
|
549
|
+
}
|
|
550
|
+
|
|
511
551
|
updated(_changedProperties) {
|
|
512
552
|
super.updated(_changedProperties);
|
|
513
553
|
|
|
@@ -525,6 +565,8 @@ class AuroForm extends r {
|
|
|
525
565
|
|
|
526
566
|
onSlotChange() {
|
|
527
567
|
this.initializeState();
|
|
568
|
+
// Safe to call as we remove and re-add event listeners
|
|
569
|
+
this._attachEventListeners();
|
|
528
570
|
}
|
|
529
571
|
|
|
530
572
|
// function that renders the HTML and CSS into the scope of the component
|
|
@@ -155,6 +155,8 @@ class AuroForm extends r {
|
|
|
155
155
|
// Bind listeners
|
|
156
156
|
this.reset = this.reset.bind(this);
|
|
157
157
|
this.submit = this.submit.bind(this);
|
|
158
|
+
this.sharedInputListener = this.sharedInputListener.bind(this);
|
|
159
|
+
this.sharedValidationListener = this.sharedValidationListener.bind(this);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
// Note: button is NOT considered a form element in this context
|
|
@@ -164,7 +166,12 @@ class AuroForm extends r {
|
|
|
164
166
|
'auro-input',
|
|
165
167
|
'auro-select',
|
|
166
168
|
'auro-datepicker',
|
|
169
|
+
'auro-combobox',
|
|
170
|
+
// checkbox and radio are grouped elements
|
|
167
171
|
'auro-checkbox-group',
|
|
172
|
+
'auro-radio-group',
|
|
173
|
+
// while counter is groupable, the group is for min/max values and not for grouped values
|
|
174
|
+
'auro-counter-group'
|
|
168
175
|
];
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -199,6 +206,18 @@ class AuroForm extends r {
|
|
|
199
206
|
return this._isInElementCollection(AuroForm.formElementTags, element);
|
|
200
207
|
}
|
|
201
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Validates if an event is from a valid form element with a name.
|
|
211
|
+
* @param {Event} event - The event to validate.
|
|
212
|
+
* @returns {boolean} - True if event is valid for processing.
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
_eventIsValidFormEvent(event) {
|
|
216
|
+
const targetName = event.target.getAttribute("name");
|
|
217
|
+
return this.isFormElement(event.target) && targetName;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
202
221
|
static get buttonElementTags() {
|
|
203
222
|
return [
|
|
204
223
|
'button',
|
|
@@ -358,7 +377,7 @@ class AuroForm extends r {
|
|
|
358
377
|
}
|
|
359
378
|
|
|
360
379
|
this.formState[targetName] = {
|
|
361
|
-
value: element.getAttribute('value'),
|
|
380
|
+
value: element.value || element.getAttribute('value'),
|
|
362
381
|
validity: element.validity || null,
|
|
363
382
|
required: element.hasAttribute('required'),
|
|
364
383
|
// element
|
|
@@ -466,48 +485,69 @@ class AuroForm extends r {
|
|
|
466
485
|
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroForm);
|
|
467
486
|
}
|
|
468
487
|
|
|
469
|
-
|
|
470
|
-
|
|
488
|
+
/**
|
|
489
|
+
* Shared input listener for all form elements.
|
|
490
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
491
|
+
*/
|
|
492
|
+
sharedInputListener(event) {
|
|
493
|
+
const targetName = event.target.getAttribute("name");
|
|
471
494
|
|
|
472
|
-
|
|
495
|
+
// This should only happen if some bubble-up event is fired from inside a form element.
|
|
496
|
+
if (!this._eventIsValidFormEvent(event)) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
473
499
|
|
|
474
|
-
//
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
500
|
+
// Occasionally, a form element will emit their event before the form can read data about the form element.
|
|
501
|
+
if (!this.formState[targetName] && this.isFormElement(event.target)) {
|
|
502
|
+
this._addElementToState(event.target);
|
|
503
|
+
}
|
|
480
504
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
505
|
+
// Check special input types and handle their edge cases
|
|
506
|
+
if (this._isElementTag('auro-datepicker', event.target) && event.target.hasAttribute('range')) {
|
|
507
|
+
this.formState[targetName].value = event.target.values;
|
|
508
|
+
this.requestUpdate('formState');
|
|
509
|
+
} else {
|
|
510
|
+
this.formState[targetName].value = event.target.value;
|
|
511
|
+
this.requestUpdate('formState');
|
|
512
|
+
}
|
|
513
|
+
}
|
|
485
514
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
515
|
+
/**
|
|
516
|
+
* Shared validation listener for all form elements.
|
|
517
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
518
|
+
*/
|
|
519
|
+
sharedValidationListener(event) {
|
|
520
|
+
const targetName = event.target.getAttribute("name");
|
|
521
|
+
if (!this._eventIsValidFormEvent(event)) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
495
524
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
525
|
+
if (!this.formState[targetName]) {
|
|
526
|
+
this._addElementToState(event.target);
|
|
527
|
+
}
|
|
501
528
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
529
|
+
this.formState[targetName].validity = event.detail.validity;
|
|
530
|
+
this._calculateValidity();
|
|
531
|
+
}
|
|
505
532
|
|
|
506
|
-
|
|
507
|
-
|
|
533
|
+
_attachEventListeners() {
|
|
534
|
+
this.queryAuroElements().forEach((element) => {
|
|
535
|
+
// remove any existing event listeners (in case of re-initialization)
|
|
536
|
+
element.removeEventListener('input', this.sharedInputListener);
|
|
537
|
+
element.removeEventListener('auroFormElement-validated', this.sharedValidationListener);
|
|
538
|
+
|
|
539
|
+
// add new event listeners
|
|
540
|
+
element.addEventListener('input', this.sharedInputListener);
|
|
541
|
+
element.addEventListener('auroFormElement-validated', this.sharedValidationListener);
|
|
508
542
|
});
|
|
509
543
|
}
|
|
510
544
|
|
|
545
|
+
firstUpdated(_changedProperties) {
|
|
546
|
+
super.firstUpdated(_changedProperties);
|
|
547
|
+
|
|
548
|
+
this._attachEventListeners();
|
|
549
|
+
}
|
|
550
|
+
|
|
511
551
|
updated(_changedProperties) {
|
|
512
552
|
super.updated(_changedProperties);
|
|
513
553
|
|
|
@@ -525,6 +565,8 @@ class AuroForm extends r {
|
|
|
525
565
|
|
|
526
566
|
onSlotChange() {
|
|
527
567
|
this.initializeState();
|
|
568
|
+
// Safe to call as we remove and re-add event listeners
|
|
569
|
+
this._attachEventListeners();
|
|
528
570
|
}
|
|
529
571
|
|
|
530
572
|
// function that renders the HTML and CSS into the scope of the component
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import {AuroInput} from "@aurodesignsystem/auro-input";
|
|
2
2
|
import {AuroDatePicker} from "@aurodesignsystem/auro-datepicker";
|
|
3
|
+
import {AuroCounter, AuroCounterGroup} from "@aurodesignsystem/auro-counter";
|
|
4
|
+
import {AuroCheckbox, AuroCheckboxGroup} from "@aurodesignsystem/auro-checkbox";
|
|
5
|
+
import {AuroCombobox} from "@aurodesignsystem/auro-combobox";
|
|
6
|
+
import {AuroMenu, AuroMenuOption} from "@aurodesignsystem/auro-menu";
|
|
7
|
+
import {AuroSelect} from "@aurodesignsystem/auro-select";
|
|
3
8
|
|
|
4
9
|
AuroInput.register();
|
|
5
10
|
AuroInput.register('auro-input-two');
|
|
6
11
|
AuroDatePicker.register();
|
|
12
|
+
AuroCounter.register();
|
|
13
|
+
AuroCounterGroup.register();
|
|
14
|
+
AuroCheckbox.register();
|
|
15
|
+
AuroCheckboxGroup.register();
|
|
16
|
+
AuroCombobox.register();
|
|
17
|
+
AuroMenu.register();
|
|
18
|
+
AuroMenuOption.register();
|
|
19
|
+
AuroSelect.register();
|
|
@@ -68,6 +68,16 @@ export class AuroForm extends LitElement {
|
|
|
68
68
|
* Submit fires an event called `submit` - just as you would expect from a normal form.
|
|
69
69
|
*/
|
|
70
70
|
submit(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Shared input listener for all form elements.
|
|
73
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
74
|
+
*/
|
|
75
|
+
sharedInputListener(event: Event): void;
|
|
76
|
+
/**
|
|
77
|
+
* Shared validation listener for all form elements.
|
|
78
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
79
|
+
*/
|
|
80
|
+
sharedValidationListener(event: Event): void;
|
|
71
81
|
/**
|
|
72
82
|
* Compare tag name with element to identify it (for API purposes).
|
|
73
83
|
* @param {string} elementTag - The HTML tag name like `auro-datepicker`.
|
|
@@ -90,6 +100,13 @@ export class AuroForm extends LitElement {
|
|
|
90
100
|
* @returns {boolean}
|
|
91
101
|
*/
|
|
92
102
|
isFormElement(element: HTMLElement): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Validates if an event is from a valid form element with a name.
|
|
105
|
+
* @param {Event} event - The event to validate.
|
|
106
|
+
* @returns {boolean} - True if event is valid for processing.
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
private _eventIsValidFormEvent;
|
|
93
110
|
/**
|
|
94
111
|
* Check if the tag name is a button element.
|
|
95
112
|
* @param {HTMLElement} element - The element to check.
|
|
@@ -148,6 +165,7 @@ export class AuroForm extends LitElement {
|
|
|
148
165
|
* Initialize (or reinitialize) the form state.
|
|
149
166
|
*/
|
|
150
167
|
initializeState(): void;
|
|
168
|
+
_attachEventListeners(): void;
|
|
151
169
|
firstUpdated(_changedProperties: any): void;
|
|
152
170
|
updated(_changedProperties: any): void;
|
|
153
171
|
onSlotChange(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auro-form.d.ts","sourceRoot":"","sources":["../src/auro-form.js"],"names":[],"mappings":"AAcA;;;;;;GAMG;AAEH;;GAEG;AAIH;;;;;GAKG;AAGH;IACE;;;;;;;;;;;;;;;;;;;MASC;
|
|
1
|
+
{"version":3,"file":"auro-form.d.ts","sourceRoot":"","sources":["../src/auro-form.js"],"names":[],"mappings":"AAcA;;;;;;GAMG;AAEH;;GAEG;AAIH;;;;;GAKG;AAGH;IACE;;;;;;;;;;;;;;;;;;;MASC;IA8BD,uCAYC;IA6CD,yCAKC;IAWD,+CAEC;IA6OD;;;;;;;OAOG;IACH,uBANW,MAAM,QAQhB;IA3VC,wBAAwB;IACxB,WADW,SAAS,CACD;IAEnB,yCAAyC;IACzC,WADW,OAAO,GAAG,SAAS,GAAG,IAAI,CAChB;IACrB,yBAA2B;IAE3B,oDAAoD;IACpD,WADW,CAAC,WAAW,GAAG;QAAC,KAAK,EAAE,MAAM,IAAI,CAAA;KAAC,CAAC,EAAE,CAC7B;IAEnB,kCAAkC;IAClC,iBADW,iBAAiB,EAAE,CACL;IAEzB,kCAAkC;IAClC,gBADW,iBAAiB,EAAE,CACN;IA+Q1B;;OAEG;IACH,cAuBC;IAED;;OAEG;IACH,eAmBC;IAcD;;;OAGG;IACH,2BAFW,KAAK,QAuBf;IAED;;;OAGG;IACH,gCAFW,KAAK,QAcf;IAjWD;;;;;;OAMG;IACH,sBAEC;IAED;;;;;;OAMG;IACH,+BAEC;IAED;;;;OAIG;IACH,uBAHW,WAAW,GACT,OAAO,CAInB;IAED;;;;;OAKG;IACH,+BAGC;IAUD;;;;OAIG;IACH,yBAHW,WAAW,GACT,OAAO,CAInB;IAMD;;;;;;;;OAQG;IACH,aAFa,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,CAOvE;IAED;;;OAGG;IACH,sBAFa,iBAAiB,EAAE,CAI/B;IAED;;;OAGG;IACH,qBAFa,iBAAiB,EAAE,CAI/B;IAED;;;OAGG;IACH,2BAcC;IAED;;;OAGG;IACH,gBAFa,OAAO,GAAG,SAAS,CAO/B;IAED,yBAUC;IAED;;;OAGG;IACH,sBAFa,OAAO,CAInB;IAED,kCAgBC;IAED;;;OAGG;IACH,qBAFa,QAAQ,CAsBpB;IAED;;;;OAIG;IACH,2BAcC;IAED;;OAEG;IACH,wBA8BC;IA+GD,8BAUC;IAED,4CAIC;IAED,uCAaC;IAED,qBAIC;IAGD,+CAMC;CACF;;;;;;;;WA5da,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI;;;;cAC3C,aAAa;;;;cACb,OAAO;;;;aACP,WAAW;;;;;;;;2BAXQ,KAAK"}
|
|
@@ -155,6 +155,8 @@ class AuroForm extends r {
|
|
|
155
155
|
// Bind listeners
|
|
156
156
|
this.reset = this.reset.bind(this);
|
|
157
157
|
this.submit = this.submit.bind(this);
|
|
158
|
+
this.sharedInputListener = this.sharedInputListener.bind(this);
|
|
159
|
+
this.sharedValidationListener = this.sharedValidationListener.bind(this);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
// Note: button is NOT considered a form element in this context
|
|
@@ -164,7 +166,12 @@ class AuroForm extends r {
|
|
|
164
166
|
'auro-input',
|
|
165
167
|
'auro-select',
|
|
166
168
|
'auro-datepicker',
|
|
169
|
+
'auro-combobox',
|
|
170
|
+
// checkbox and radio are grouped elements
|
|
167
171
|
'auro-checkbox-group',
|
|
172
|
+
'auro-radio-group',
|
|
173
|
+
// while counter is groupable, the group is for min/max values and not for grouped values
|
|
174
|
+
'auro-counter-group'
|
|
168
175
|
];
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -199,6 +206,18 @@ class AuroForm extends r {
|
|
|
199
206
|
return this._isInElementCollection(AuroForm.formElementTags, element);
|
|
200
207
|
}
|
|
201
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Validates if an event is from a valid form element with a name.
|
|
211
|
+
* @param {Event} event - The event to validate.
|
|
212
|
+
* @returns {boolean} - True if event is valid for processing.
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
_eventIsValidFormEvent(event) {
|
|
216
|
+
const targetName = event.target.getAttribute("name");
|
|
217
|
+
return this.isFormElement(event.target) && targetName;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
202
221
|
static get buttonElementTags() {
|
|
203
222
|
return [
|
|
204
223
|
'button',
|
|
@@ -358,7 +377,7 @@ class AuroForm extends r {
|
|
|
358
377
|
}
|
|
359
378
|
|
|
360
379
|
this.formState[targetName] = {
|
|
361
|
-
value: element.getAttribute('value'),
|
|
380
|
+
value: element.value || element.getAttribute('value'),
|
|
362
381
|
validity: element.validity || null,
|
|
363
382
|
required: element.hasAttribute('required'),
|
|
364
383
|
// element
|
|
@@ -466,48 +485,69 @@ class AuroForm extends r {
|
|
|
466
485
|
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroForm);
|
|
467
486
|
}
|
|
468
487
|
|
|
469
|
-
|
|
470
|
-
|
|
488
|
+
/**
|
|
489
|
+
* Shared input listener for all form elements.
|
|
490
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
491
|
+
*/
|
|
492
|
+
sharedInputListener(event) {
|
|
493
|
+
const targetName = event.target.getAttribute("name");
|
|
471
494
|
|
|
472
|
-
|
|
495
|
+
// This should only happen if some bubble-up event is fired from inside a form element.
|
|
496
|
+
if (!this._eventIsValidFormEvent(event)) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
473
499
|
|
|
474
|
-
//
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
500
|
+
// Occasionally, a form element will emit their event before the form can read data about the form element.
|
|
501
|
+
if (!this.formState[targetName] && this.isFormElement(event.target)) {
|
|
502
|
+
this._addElementToState(event.target);
|
|
503
|
+
}
|
|
480
504
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
505
|
+
// Check special input types and handle their edge cases
|
|
506
|
+
if (this._isElementTag('auro-datepicker', event.target) && event.target.hasAttribute('range')) {
|
|
507
|
+
this.formState[targetName].value = event.target.values;
|
|
508
|
+
this.requestUpdate('formState');
|
|
509
|
+
} else {
|
|
510
|
+
this.formState[targetName].value = event.target.value;
|
|
511
|
+
this.requestUpdate('formState');
|
|
512
|
+
}
|
|
513
|
+
}
|
|
485
514
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
515
|
+
/**
|
|
516
|
+
* Shared validation listener for all form elements.
|
|
517
|
+
* @param {Event} event - The event that is fired from the form element.
|
|
518
|
+
*/
|
|
519
|
+
sharedValidationListener(event) {
|
|
520
|
+
const targetName = event.target.getAttribute("name");
|
|
521
|
+
if (!this._eventIsValidFormEvent(event)) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
495
524
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
525
|
+
if (!this.formState[targetName]) {
|
|
526
|
+
this._addElementToState(event.target);
|
|
527
|
+
}
|
|
501
528
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
529
|
+
this.formState[targetName].validity = event.detail.validity;
|
|
530
|
+
this._calculateValidity();
|
|
531
|
+
}
|
|
505
532
|
|
|
506
|
-
|
|
507
|
-
|
|
533
|
+
_attachEventListeners() {
|
|
534
|
+
this.queryAuroElements().forEach((element) => {
|
|
535
|
+
// remove any existing event listeners (in case of re-initialization)
|
|
536
|
+
element.removeEventListener('input', this.sharedInputListener);
|
|
537
|
+
element.removeEventListener('auroFormElement-validated', this.sharedValidationListener);
|
|
538
|
+
|
|
539
|
+
// add new event listeners
|
|
540
|
+
element.addEventListener('input', this.sharedInputListener);
|
|
541
|
+
element.addEventListener('auroFormElement-validated', this.sharedValidationListener);
|
|
508
542
|
});
|
|
509
543
|
}
|
|
510
544
|
|
|
545
|
+
firstUpdated(_changedProperties) {
|
|
546
|
+
super.firstUpdated(_changedProperties);
|
|
547
|
+
|
|
548
|
+
this._attachEventListeners();
|
|
549
|
+
}
|
|
550
|
+
|
|
511
551
|
updated(_changedProperties) {
|
|
512
552
|
super.updated(_changedProperties);
|
|
513
553
|
|
|
@@ -525,6 +565,8 @@ class AuroForm extends r {
|
|
|
525
565
|
|
|
526
566
|
onSlotChange() {
|
|
527
567
|
this.initializeState();
|
|
568
|
+
// Safe to call as we remove and re-add event listeners
|
|
569
|
+
this._attachEventListeners();
|
|
528
570
|
}
|
|
529
571
|
|
|
530
572
|
// function that renders the HTML and CSS into the scope of the component
|