Skip to content

Commit 895ff7c

Browse files
authored
Merge pull request #3424 from TechnologyEnhancedLearning/Develop/Fix/TD-5308-Edit-the-branding-errors
TD-5308-Validation added to check for whitespaces while adding new brands and categories.
2 parents 28dd9ca + dc75541 commit 895ff7c

File tree

1 file changed

+39
-0
lines changed
  • DigitalLearningSolutions.Web/Scripts/frameworks

1 file changed

+39
-0
lines changed

DigitalLearningSolutions.Web/Scripts/frameworks/branding.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ function brandChanged() {
1010
if (style === 'block') {
1111
tb.value = '';
1212
tb.required = true;
13+
tb.setCustomValidity("");
1314
tb.focus();
1415
} else {
16+
tb.value = "";
17+
tb.setCustomValidity("");
1518
tb.required = false;
1619
}
1720
}
@@ -27,8 +30,11 @@ function categoryChanged() {
2730
if (style === 'block') {
2831
tb.value = '';
2932
tb.required = true;
33+
tb.setCustomValidity("");
3034
tb.focus();
3135
} else {
36+
tb.value = "";
37+
tb.setCustomValidity("");
3238
tb.required = false;
3339
}
3440
}
@@ -44,8 +50,41 @@ function topicChanged() {
4450
if (style === 'block') {
4551
tb.value = '';
4652
tb.required = true;
53+
tb.setCustomValidity("");
4754
tb.focus();
4855
} else {
56+
tb.value = "";
57+
tb.setCustomValidity("");
4958
tb.required = false;
5059
}
5160
}
61+
const form = document.querySelector("form") as HTMLFormElement;
62+
const bfield = <HTMLInputElement>document.getElementById('brand-field');
63+
const cfield = <HTMLInputElement>document.getElementById('category-field');
64+
const tfield = <HTMLInputElement>document.getElementById('topic-field');
65+
function wireClearOnInput(input: HTMLInputElement) {
66+
input.addEventListener("input", () => {
67+
input.setCustomValidity("");
68+
});
69+
}
70+
71+
if (bfield) wireClearOnInput(bfield);
72+
if (cfield) wireClearOnInput(cfield);
73+
if (tfield) wireClearOnInput(tfield);
74+
75+
form.addEventListener("submit", (e: Event) => {
76+
[
77+
{ el: bfield, msg: "Please enter a valid brand." },
78+
{ el: cfield, msg: "Please enter a valid category." },
79+
{ el: tfield, msg: "Please enter a valid topic." }
80+
].forEach(f => {
81+
if (f.el.required && !f.el.value.trim()) {
82+
e.preventDefault();
83+
f.el.setCustomValidity(f.msg);
84+
f.el.reportValidity();
85+
f.el.focus();
86+
} else {
87+
f.el.setCustomValidity("");
88+
}
89+
});
90+
});

0 commit comments

Comments
 (0)