Skip to content

Commit 3ce4e4a

Browse files
committed
maint(pat-validation): Rename set_validity to set_error, which better suites the functionality.
1 parent e585a67 commit 3ce4e4a

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/pat/validation/validation.js

Lines changed: 15 additions & 14 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_validity({ input: input, msg: "" });
116+
this.set_error({ input: input, msg: "" });
117117
const validity_state = input.validity;
118118

119119
if (event?.submitter?.hasAttribute("formnovalidate")) {
@@ -148,7 +148,7 @@ class Pattern extends BasePattern {
148148
const message =
149149
input_options.message.equality ||
150150
`The value is not equal to %{attribute}`;
151-
this.set_validity({
151+
this.set_error({
152152
input: input,
153153
msg: message,
154154
attribute: input_options.equality,
@@ -216,7 +216,7 @@ class Pattern extends BasePattern {
216216
);
217217
msg_attr = msg_attr || not_after_el.name;
218218
}
219-
this.set_validity({
219+
this.set_error({
220220
input: input,
221221
msg: msg || msg_default_not_after,
222222
attribute: msg_attr.trim(),
@@ -237,7 +237,7 @@ class Pattern extends BasePattern {
237237
);
238238
msg_attr = msg_attr || not_before_el.name;
239239
}
240-
this.set_validity({
240+
this.set_error({
241241
input: input,
242242
msg: msg || msg_default_not_before,
243243
attribute: msg_attr.trim(),
@@ -266,15 +266,15 @@ class Pattern extends BasePattern {
266266
// Default error cases with custom messages.
267267

268268
if (validity_state.valueMissing && input_options.message.required) {
269-
this.set_validity({ input: input, msg: input_options.message.required });
269+
this.set_error({ input: input, msg: input_options.message.required });
270270
} else if (validity_state.rangeUnderflow && input_options.message.min) {
271-
this.set_validity({
271+
this.set_error({
272272
input: input,
273273
msg: input_options.message.min,
274274
min: input.getAttribute("min"),
275275
});
276276
} else if (validity_state.rangeOverflow && input_options.message.max) {
277-
this.set_validity({
277+
this.set_error({
278278
input: input,
279279
msg: input_options.message.max,
280280
max: input.getAttribute("max"),
@@ -284,37 +284,37 @@ class Pattern extends BasePattern {
284284
input.type === "number" &&
285285
input_options.message.number
286286
) {
287-
this.set_validity({ input: input, msg: input_options.message.number });
287+
this.set_error({ input: input, msg: input_options.message.number });
288288
} else if (
289289
validity_state.typeMismatch &&
290290
input.type === "email" &&
291291
input_options.message.email
292292
) {
293-
this.set_validity({ input: input, msg: input_options.message.email });
293+
this.set_error({ input: input, msg: input_options.message.email });
294294
} else if (
295295
validity_state.rangeUnderflow &&
296296
input.type === "date" &&
297297
input_options.message.date
298298
) {
299-
this.set_validity({ input: input, msg: input_options.message.date });
299+
this.set_error({ input: input, msg: input_options.message.date });
300300
} else if (
301301
validity_state.rangeOverflow &&
302302
input.type === "date" &&
303303
input_options.message.date
304304
) {
305-
this.set_validity({ input: input, msg: input_options.message.date });
305+
this.set_error({ input: input, msg: input_options.message.date });
306306
} else if (
307307
validity_state.rangeUnderflow &&
308308
input.type === "datetime" &&
309309
input_options.message.datetime
310310
) {
311-
this.set_validity({ input: input, msg: input_options.message.datetime });
311+
this.set_error({ input: input, msg: input_options.message.datetime });
312312
} else if (
313313
validity_state.rangeOverflow &&
314314
input.type === "datetime" &&
315315
input_options.message.datetime
316316
) {
317-
this.set_validity({ input: input, msg: input_options.message.datetime });
317+
this.set_error({ input: input, msg: input_options.message.datetime });
318318
}
319319
}
320320

@@ -327,7 +327,7 @@ class Pattern extends BasePattern {
327327
this.set_error_message(input);
328328
}
329329

330-
set_validity({ input, msg, attribute = null, min = null, max = null }) {
330+
set_error({ input, msg, attribute = null, min = null, max = null }) {
331331
// Replace some variables, as like validate.js
332332
if (attribute) {
333333
msg = msg.replace(/%{attribute}/g, attribute);
@@ -345,6 +345,7 @@ class Pattern extends BasePattern {
345345
// Hidden inputs do not participate in validation but we need this
346346
// (e.g. styled date input).
347347
input[KEY_ERROR_MSG] = msg;
348+
348349
}
349350

350351
remove_error(input, all_of_group = false) {

0 commit comments

Comments
 (0)