Skip to content

Commit 85f1959

Browse files
committed
fix(pat-validation): Put error messages always at the end of a group of inputs with the samne name.
1 parent e91954f commit 85f1959

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/pat/validation/documentation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ In addition both the input element and its label will get an `warning` class.
8989
</label>
9090
```
9191

92-
Checkboxes and radio buttons are treated differently: if they are contained in a fieldset with class `checklist` error messages are added at the end of the fieldset.
92+
Checkboxes and radio buttons are treated differently: The error message is alywas set after the last element of the inputs with the same name.
9393

9494
```html
95-
<fieldset class="checklist radio">
95+
<fieldset>
9696
<label><input type="radio" name="radio" /> Strawberry</label>
9797
<label><input type="radio" name="radio" /> Banana</label>
9898
<label><input type="radio" name="radio" /> Raspberry</label>

src/pat/validation/validation.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,9 @@ class Pattern extends BasePattern {
475475
this.error_template(validation_message)
476476
).firstChild;
477477

478-
let fieldset;
479-
if (input.type === "radio" || input.type === "checkbox") {
480-
fieldset = input.closest("fieldset.pat-checklist");
481-
}
482-
if (fieldset) {
483-
fieldset.append(error_node);
484-
} else {
485-
input.after(error_node);
486-
}
478+
// Put error messge after the erronous input or - in case of multiple
479+
// inputs with the same name - after the last one of the group.
480+
inputs.pop().after(error_node);
487481
input[KEY_ERROR_EL] = error_node;
488482

489483
let did_disable = false;

0 commit comments

Comments
 (0)