Skip to content

Commit 31254a4

Browse files
committed
feat(pat-validation): Emit pat-update events with actions invalid and valid after validation checks on inputs.
1 parent 9fb5fda commit 31254a4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/pat/validation/validation.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Pattern extends BasePattern {
113113
}
114114

115115
// In any case, clear the custom validity first.
116-
this.set_error({ input: input, msg: "" });
116+
this.set_error({ input: input, msg: "", skip_event: true });
117117
const validity_state = input.validity;
118118

119119
if (event?.submitter?.hasAttribute("formnovalidate")) {
@@ -327,7 +327,7 @@ class Pattern extends BasePattern {
327327
this.set_error_message(input);
328328
}
329329

330-
set_error({ input, msg, attribute = null, min = null, max = null }) {
330+
set_error({ input, msg, attribute = null, min = null, max = null, skip_event = false }) {
331331
// Replace some variables, as like validate.js
332332
if (attribute) {
333333
msg = msg.replace(/%{attribute}/g, attribute);
@@ -346,9 +346,12 @@ class Pattern extends BasePattern {
346346
// (e.g. styled date input).
347347
input[KEY_ERROR_MSG] = msg;
348348

349+
if (!skip_event) {
350+
this.emit_update("invalid");
351+
}
349352
}
350353

351-
remove_error(input, all_of_group = false) {
354+
remove_error(input, all_of_group = false, skip_event = false) {
352355
// Remove error message and related referencesfrom input.
353356

354357
let inputs = [input];
@@ -371,6 +374,10 @@ class Pattern extends BasePattern {
371374
}
372375
}
373376
}
377+
378+
if (!skip_event) {
379+
this.emit_update("valid");
380+
}
374381
}
375382

376383
set_error_message(input) {

0 commit comments

Comments
 (0)