|
8 | 8 | <script type="module"> |
9 | 9 | import {ErrorHandlingElement} from "../src/error-handling-element.js" |
10 | 10 | import {clearErrorListsInForm} from "../src/rendering.js" |
| 11 | + import {applyErrorMappingToForm} from "../src/error-mapping.js" |
11 | 12 |
|
12 | 13 | class CustomErrorHandleElement extends ErrorHandlingElement { |
13 | 14 | connectedCallback() { |
|
27 | 28 | if (!window.customElements.get('custom-error-handling')) { |
28 | 29 | window.customElements.define('custom-error-handling', CustomErrorHandleElement); |
29 | 30 | } |
| 31 | + |
| 32 | + const errors = [ |
| 33 | + { |
| 34 | + container_id: "email-field-errors", |
| 35 | + element_to_invalidate_id: "email-field", |
| 36 | + message: "This email has been taken", |
| 37 | + type: "taken" |
| 38 | + }, |
| 39 | + { |
| 40 | + container_id: "email-field-errors", |
| 41 | + element_to_invalidate_id: "email-field", |
| 42 | + message: "Email is too short (pulled from server messages)", |
| 43 | + type: "tooShort" |
| 44 | + }, |
| 45 | + { |
| 46 | + container_id: "test-form-error-container", |
| 47 | + element_to_invalidate_id: "test-form", |
| 48 | + message: "General errors from the server-side", |
| 49 | + type: "general" |
| 50 | + }, |
| 51 | + { |
| 52 | + container_id: "random-missing-field-errors", |
| 53 | + element_to_invalidate_id: "random-missing-field", |
| 54 | + message: "Errors that need to go in the fallback section", |
| 55 | + type: "api_error" |
| 56 | + }, |
| 57 | + ] |
| 58 | + |
| 59 | + const applyErrorMappingButton = document.getElementById(`apply-error-mapping`) |
| 60 | + const form = document.getElementById(`test-form`) |
| 61 | + |
| 62 | + applyErrorMappingButton.addEventListener(`click`, (event) => { |
| 63 | + applyErrorMappingToForm(form, errors) |
| 64 | + document.getElementById(`easy-console`).value += "Applied error map\n" |
| 65 | + }) |
30 | 66 | </script> |
31 | 67 |
|
32 | 68 | <style> |
@@ -67,8 +103,13 @@ <h2>Form Errors</h2> |
67 | 103 | </form> |
68 | 104 | </custom-error-handling> |
69 | 105 |
|
| 106 | + <p> |
| 107 | + <button id="apply-error-mapping">Apply error mapping</button> |
| 108 | + </p> |
| 109 | + |
70 | 110 | <textarea id="easy-console" readonly rows=20></textarea> |
71 | 111 |
|
| 112 | + |
72 | 113 | <template id="pf-error-list-item-template"> |
73 | 114 | <li><span>‼️</span> <span data-error-message></span></li> |
74 | 115 | </template> |
|
0 commit comments