@brightspace-ui/core 3.301.0 → 3.302.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.
@@ -144,3 +144,7 @@ Within the fieldset, `<d2l-input-group>` can still be used to provide a consiste
144
144
  * `Default`: Related input components
145
145
  * `inline-help`: Help text that will appear below the input. Use this only when other helpful cues are not sufficient, such as a carefully-worded label.
146
146
  <!-- docs: end hidden content -->
147
+
148
+ ## Custom Validation [validation-custom]
149
+
150
+ To attach custom validation logic to an existing component (native or custom), use [d2l-validation-custom](../../../components/validation).
@@ -1,25 +1,21 @@
1
1
  # Validation
2
- ## d2l-validation-custom
2
+ ## Validation Custom [d2l-validation-custom]
3
3
 
4
- The `d2l-validation-custom` component is used to add custom validation logic to native form elements like `input`, `select` and `textarea` or custom form elements created with the [`FormElementMixin`](../form/docs/form-element-mixin.md).
4
+ The `d2l-validation-custom` component is used to add custom validation logic to native form elements like `input`, `select` and `textarea` or custom form elements created with the [`FormElementMixin`](https://github.com/BrightspaceUI/core/blob/main/components/form/docs/form-element-mixin.md).
5
5
 
6
6
  **Native Form Elements:**
7
- - When attached to native form elements like `input`, `select` and `textarea`, both the `d2l-validation-custom` and native form element **must** be within a [`d2l-form`](../form/docs/form.md) for the validation custom to function.
7
+ - When attached to native form elements like `input`, `select` and `textarea`, both the `d2l-validation-custom` and native form element **must** be within a [`d2l-form`](../../components/form-layout-validation) for the validation custom to function.
8
8
 
9
9
  **Custom Form Elements:**
10
- - When attached to custom form elements created with the [`FormElementMixin`](../form/docs/form-element-mixin.md), the `d2l-validation-custom` will function even if no [`d2l-form`](../form/docs/form.md) is present.
10
+ - When attached to custom form elements created with the [`FormElementMixin`](https://github.com/BrightspaceUI/core/blob/main/components/form/docs/form-element-mixin.md), the `d2l-validation-custom` will function even if no [`d2l-form`](../../components/form-layout-validation) is present.
11
11
 
12
12
  **Usage:**
13
+ <!-- docs: demo code properties autoSize:false size:small name:d2l-validation-custom sandboxTitle:'Custom Validation' -->
13
14
  ```html
14
15
  <script type="module">
16
+ import '@brightspace-ui/core/components/inputs/input-text.js';
15
17
  import '@brightspace-ui/core/components/validation/validation-custom.js';
16
- </script>
17
-
18
- <d2l-input-text id="my-text-input"></d2l-input-text>
19
- <d2l-validation-custom for="my-text-input" failure-text="My custom error message">
20
- </d2l-validation-custom>
21
18
 
22
- <script>
23
19
  const validator = document.querySelector('d2l-validation-custom');
24
20
  validator.addEventListener('d2l-validation-custom-validate', e => {
25
21
  // Implement your custom validation logic
@@ -28,8 +24,12 @@ The `d2l-validation-custom` component is used to add custom validation logic to
28
24
  e.detail.resolve(isValid);
29
25
  });
30
26
  </script>
31
- ```
32
27
 
28
+ <d2l-input-text id="my-text-input" label="name" style="max-width: 200px;"></d2l-input-text>
29
+ <d2l-validation-custom for="my-text-input" failure-text="My custom error message">
30
+ </d2l-validation-custom>
31
+ ```
32
+ <!-- docs: start hidden content -->
33
33
  **Properties:**
34
34
 
35
35
  | Property | Type | Description |
@@ -42,7 +42,9 @@ The `d2l-validation-custom` component is used to add custom validation logic to
42
42
  * The form element being validated can be accessed from the `detail`'s `forElement` property.
43
43
  * When validation is finished, the `detail`'s `resolve` function **must** be called with a `boolean` value to indicate valid or invalid. If it is not called then validation will never complete and the component will be stuck in a validating state.
44
44
 
45
- ## ValidationCustomMixin
45
+ <!-- docs: end hidden content -->
46
+
47
+ ## Validation Custom Mixin [ValidationCustomMixin]
46
48
 
47
49
  If you find yourself duplicating `d2l-validation-custom` validation logic in many places you may want to create your own custom validator using the `ValidationCustomMixin`.
48
50
 
@@ -64,7 +66,3 @@ customElements.define('my-validation-custom', MyValidationCustom);
64
66
  ```
65
67
 
66
68
  Once a component has been created using the `ValidationCustomMixin`, it may be used exactly like a `d2l-validation-custom`. However, the `d2l-validation-custom-validate` event isn't needed because the validation logic is included in the component itself.
67
-
68
- ## Future Enhancements
69
-
70
- Looking for an enhancement not listed here? Create a GitHub issue!
@@ -3,7 +3,15 @@ import { isCustomFormElement } from '../form/form-helper.js';
3
3
  export const ValidationCustomMixin = superclass => class extends superclass {
4
4
 
5
5
  static properties = {
6
+ /**
7
+ * REQUIRED: The text to display when validation fails.
8
+ * @type {string}
9
+ */
6
10
  failureText: { type: String, attribute: 'failure-text' },
11
+ /**
12
+ * REQUIRED: The id of the form element to validate.
13
+ * @type {string}
14
+ */
7
15
  for: { type: String }
8
16
  };
9
17
 
@@ -19,6 +27,7 @@ export const ValidationCustomMixin = superclass => class extends superclass {
19
27
  connectedCallback() {
20
28
  super.connectedCallback();
21
29
  this._updateForElement();
30
+ /**@ignore */
22
31
  this.dispatchEvent(new CustomEvent('d2l-validation-custom-connected', { bubbles: true }));
23
32
  }
24
33
 
@@ -28,6 +37,7 @@ export const ValidationCustomMixin = superclass => class extends superclass {
28
37
  this._forElement.validationCustomDisconnected(this);
29
38
  }
30
39
  this._forElement = null;
40
+ /**@ignore */
31
41
  this.dispatchEvent(new CustomEvent('d2l-validation-custom-disconnected'));
32
42
  }
33
43
 
@@ -2,6 +2,10 @@
2
2
  import { css, LitElement } from 'lit';
3
3
  import { ValidationCustomMixin } from './validation-custom-mixin.js';
4
4
 
5
+ /**
6
+ * A component that can be used to provide custom validation for a form element. The component is hidden and does not render any visible content.
7
+ * @fires d2l-validation-custom-validate - Dispatched when the component is validated.
8
+ */
5
9
  class ValidationCustom extends ValidationCustomMixin(LitElement) {
6
10
 
7
11
  static styles = css`
@@ -17387,13 +17387,16 @@
17387
17387
  {
17388
17388
  "name": "d2l-validation-custom",
17389
17389
  "path": "./components/validation/validation-custom.js",
17390
+ "description": "A component that can be used to provide custom validation for a form element. The component is hidden and does not render any visible content.",
17390
17391
  "attributes": [
17391
17392
  {
17392
17393
  "name": "failure-text",
17394
+ "description": "REQUIRED: The text to display when validation fails.",
17393
17395
  "type": "string"
17394
17396
  },
17395
17397
  {
17396
17398
  "name": "for",
17399
+ "description": "REQUIRED: The id of the form element to validate.",
17397
17400
  "type": "string"
17398
17401
  }
17399
17402
  ],
@@ -17405,11 +17408,13 @@
17405
17408
  {
17406
17409
  "name": "failureText",
17407
17410
  "attribute": "failure-text",
17411
+ "description": "REQUIRED: The text to display when validation fails.",
17408
17412
  "type": "string"
17409
17413
  },
17410
17414
  {
17411
17415
  "name": "for",
17412
17416
  "attribute": "for",
17417
+ "description": "REQUIRED: The id of the form element to validate.",
17413
17418
  "type": "string"
17414
17419
  },
17415
17420
  {
@@ -17418,13 +17423,8 @@
17418
17423
  ],
17419
17424
  "events": [
17420
17425
  {
17421
- "name": "d2l-validation-custom-validate"
17422
- },
17423
- {
17424
- "name": "d2l-validation-custom-connected"
17425
- },
17426
- {
17427
- "name": "d2l-validation-custom-disconnected"
17426
+ "name": "d2l-validation-custom-validate",
17427
+ "description": "Dispatched when the component is validated."
17428
17428
  }
17429
17429
  ]
17430
17430
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.301.0",
3
+ "version": "3.302.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",