@brightspace-ui/core 3.42.0 → 3.43.0
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/components/dialog/dialog-mixin.js +1 -0
- package/components/form/demo/form-demo.js +5 -0
- package/components/form/docs/form-element-mixin.md +1 -0
- package/components/form/docs/form.md +1 -0
- package/components/form/form-element-mixin.js +12 -0
- package/components/form/form.js +42 -0
- package/package.json +1 -1
@@ -76,6 +76,7 @@ export const DialogMixin = superclass => class extends RtlMixin(superclass) {
|
|
76
76
|
this._handleDropdownOpenClose = this._handleDropdownOpenClose.bind(this);
|
77
77
|
this._handleMvcDialogOpen = this._handleMvcDialogOpen.bind(this);
|
78
78
|
this._inIframe = false;
|
79
|
+
this._isDialogMixin = true;
|
79
80
|
this._isFullHeight = false;
|
80
81
|
this._height = 0;
|
81
82
|
this._left = 0;
|
@@ -71,6 +71,7 @@ class FormNestedDemo extends LitElement {
|
|
71
71
|
</div>
|
72
72
|
<d2l-floating-buttons always-float>
|
73
73
|
<d2l-button primary @click=${this._submit}>Save</d2l-button>
|
74
|
+
<d2l-button @click=${this._reset}>Reset</d2l-button>
|
74
75
|
</d2l-floating-buttons>
|
75
76
|
</d2l-form>
|
76
77
|
`;
|
@@ -85,6 +86,10 @@ class FormNestedDemo extends LitElement {
|
|
85
86
|
e.preventDefault();
|
86
87
|
}
|
87
88
|
|
89
|
+
_reset() {
|
90
|
+
if (this.shadowRoot) this.shadowRoot.querySelector('#root').resetValidation();
|
91
|
+
}
|
92
|
+
|
88
93
|
_submit() {
|
89
94
|
if (this.shadowRoot) this.shadowRoot.querySelector('#root').submit();
|
90
95
|
}
|
@@ -18,6 +18,7 @@ invalid state.
|
|
18
18
|
| `name` | String | The name of the form control. Submitted with the form as part of a name/value pair. |
|
19
19
|
|
20
20
|
**Methods:**
|
21
|
+
- `resetValidation()`: Resets any validation errors on the form element. Note that this does not reset any form element value.
|
21
22
|
- `setFormValue(value)`: Sets the current value of the form control. Submitted with the form as part of a name/value pair. `value` may be a:
|
22
23
|
1. An `Object`: `{ 'key1': val, 'key2': val }`
|
23
24
|
- When an `Object` is provided, all keys-value pairs will be submitted. To avoid collision it is recommended that you prefix each key with the component's `name` property value.
|
@@ -114,6 +114,7 @@ If you're looking to emulate native form element submission, `d2l-form-native` m
|
|
114
114
|
### Methods
|
115
115
|
- `submit()`: Submits the form. This will first perform validation on all elements within the form including nested `d2l-form` elements.
|
116
116
|
- **Note:** If validation succeeds, the form data will be aggregated and passed back to the caller via the `d2l-form-submit` event. It will not be submitted by the form itself.
|
117
|
+
- `resetValidation()`: Resets the validation errors. Note that this does not reset any form values. Daylight dialog components (e.g., `d2l-dialog`) will automatically run this method on close.
|
117
118
|
- `async validate()`: Validates the form and any nested `d2l-form` elements without submitting even if validation succeeds for all elements. Returns a `Map` mapping from an element to the list of error messages associated with it.
|
118
119
|
- **Note:** The return value will include elements and errors from both the root form and any nested descendant forms.
|
119
120
|
|
@@ -227,6 +227,18 @@ export const FormElementMixin = superclass => class extends LocalizeCoreElement(
|
|
227
227
|
await this.updatedComplete;
|
228
228
|
}
|
229
229
|
|
230
|
+
resetValidation() {
|
231
|
+
this.invalid = false;
|
232
|
+
this.validationError = null;
|
233
|
+
this._errors = [];
|
234
|
+
|
235
|
+
this.childErrors.forEach((_, ele) => {
|
236
|
+
if (!isCustomFormElement(ele)) return;
|
237
|
+
ele.resetValidation();
|
238
|
+
});
|
239
|
+
this.childErrors = new Map();
|
240
|
+
}
|
241
|
+
|
230
242
|
setFormValue(formValue) {
|
231
243
|
this.formValue = formValue;
|
232
244
|
}
|
package/components/form/form.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { css, html, LitElement } from 'lit';
|
2
2
|
import { findFormElements, flattenMap, getFormElementData, isCustomFormElement, isNativeFormElement } from './form-helper.js';
|
3
|
+
import { findComposedAncestor } from '../../helpers/dom.js';
|
3
4
|
import { FormMixin } from './form-mixin.js';
|
4
5
|
|
5
6
|
/**
|
@@ -55,6 +56,12 @@ class Form extends FormMixin(LitElement) {
|
|
55
56
|
this._isSubForm = false;
|
56
57
|
}
|
57
58
|
|
59
|
+
firstUpdated(changedProperties) {
|
60
|
+
super.firstUpdated(changedProperties);
|
61
|
+
|
62
|
+
this._setupDialogValidationReset();
|
63
|
+
}
|
64
|
+
|
58
65
|
render() {
|
59
66
|
let errorSummary = null;
|
60
67
|
if (this._isRootForm()) {
|
@@ -77,6 +84,26 @@ class Form extends FormMixin(LitElement) {
|
|
77
84
|
this._submitData(submitter);
|
78
85
|
}
|
79
86
|
|
87
|
+
resetValidation() {
|
88
|
+
const formElements = this._findFormElements();
|
89
|
+
for (const ele of formElements) {
|
90
|
+
if (this._hasSubForms(ele)) {
|
91
|
+
const forms = this._getSubForms(ele);
|
92
|
+
for (const form of forms) {
|
93
|
+
form.resetValidation();
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
if (isCustomFormElement(ele)) {
|
97
|
+
ele.resetValidation();
|
98
|
+
} else if (isNativeFormElement(ele)) {
|
99
|
+
this._displayValid(ele);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
this._errors = new Map();
|
104
|
+
this._tooltips = new Map();
|
105
|
+
}
|
106
|
+
|
80
107
|
async submit() {
|
81
108
|
return this.requestSubmit(null);
|
82
109
|
}
|
@@ -165,6 +192,21 @@ class Form extends FormMixin(LitElement) {
|
|
165
192
|
|
166
193
|
}
|
167
194
|
|
195
|
+
_setupDialogValidationReset() {
|
196
|
+
const flag = window.D2L?.LP?.Web?.UI?.Flags.Flag('GAUD-6979-dialog-close-reset-validation', true) ?? true;
|
197
|
+
if (!flag) return;
|
198
|
+
|
199
|
+
const dialogAncestor = findComposedAncestor(
|
200
|
+
this,
|
201
|
+
node => node?._isDialogMixin
|
202
|
+
);
|
203
|
+
if (!dialogAncestor) return;
|
204
|
+
|
205
|
+
dialogAncestor.addEventListener('d2l-dialog-close', () => {
|
206
|
+
this.resetValidation();
|
207
|
+
});
|
208
|
+
}
|
209
|
+
|
168
210
|
async _submitData(submitter) {
|
169
211
|
this._dirty = false;
|
170
212
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.43.0",
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
5
5
|
"type": "module",
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|