Skip to content

Commit 82c9449

Browse files
committed
Add error mapping to demo
1 parent 398b8b5 commit 82c9449

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

demo/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script type="module">
99
import {ErrorHandlingElement} from "../src/error-handling-element.js"
1010
import {clearErrorListsInForm} from "../src/rendering.js"
11+
import {applyErrorMappingToForm} from "../src/error-mapping.js"
1112

1213
class CustomErrorHandleElement extends ErrorHandlingElement {
1314
connectedCallback() {
@@ -27,6 +28,41 @@
2728
if (!window.customElements.get('custom-error-handling')) {
2829
window.customElements.define('custom-error-handling', CustomErrorHandleElement);
2930
}
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+
})
3066
</script>
3167

3268
<style>
@@ -67,8 +103,13 @@ <h2>Form Errors</h2>
67103
</form>
68104
</custom-error-handling>
69105

106+
<p>
107+
<button id="apply-error-mapping">Apply error mapping</button>
108+
</p>
109+
70110
<textarea id="easy-console" readonly rows=20></textarea>
71111

112+
72113
<template id="pf-error-list-item-template">
73114
<li><span>‼️</span> <span data-error-message></span></li>
74115
</template>

0 commit comments

Comments
 (0)