Skip to content

Commit de8d154

Browse files
committed
Improved rule date in validator
1 parent 308136a commit de8d154

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
### 5.1.15
22

3-
+ [x] Fix validator for the `required` rule for the `input` with role
3+
+ [x] Fix validator for the `required` rule for the `input` with role
4+
+ [x] Improved rule `date` in validator

examples/validator-{required}.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@
4747
<div class="form-group">
4848
<input type="text"
4949
data-role="input"
50-
data-validate="minlength=3"
51-
data-label="Enter data:">
52-
<span class="invalid_feedback">The length of value must be >= 3!</span>
50+
data-validate="date"
51+
data-label="Enter date:">
52+
<span class="invalid_feedback">Enter a valid date</span>
53+
</div>
54+
<div class="form-group">
55+
<input type="text" data-validate="date" data-value-format="DD, MMM YYYY">
56+
<span class="invalid_feedback">Enter a valid date</span>
5357
</div>
5458
<div class="form-group">
5559
<input type="text"

lib/metro.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42898,13 +42898,9 @@
4289842898
url: (val) => G.safeParse(G.url(), val).ok,
4289942899
date: (val, format, locale) => {
4290042900
try {
42901-
if (!format) {
42902-
datetime(val);
42903-
} else {
42904-
Datetime.from(val, format, locale);
42905-
}
42906-
return true;
42907-
} catch (e2) {
42901+
const _d = !format ? datetime(val) : Datetime.from(val, format, locale);
42902+
return !format ? true : _d.format(format, locale) === val;
42903+
} catch {
4290842904
return false;
4290942905
}
4291042906
},
@@ -42919,9 +42915,9 @@
4291942915
return Farbe.Palette.color(val, Farbe.StandardColors) || Farbe.Routines.isColor(val);
4292042916
},
4292142917
pattern: (val, pat) => G.safeParse(G.pattern(pat), val).ok,
42922-
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
42918+
// biome-ignore lint/suspicious/noDoubleEquals: required for compare
4292342919
compare: (val, val2) => val == val2,
42924-
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
42920+
// biome-ignore lint/suspicious/noDoubleEquals: required for compare
4292542921
not: (val, not_this) => val != not_this,
4292642922
notequals: (val, val2) => val !== val2,
4292742923
equals: (val, val2) => val === val2,

lib/metro.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/components/validator/validator.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
((Metro, $) => {
2-
// biome-ignore lint/suspicious/noRedundantUseStrict: <explanation>
2+
// biome-ignore lint/suspicious/noRedundantUseStrict: Required to work with string
33
"use strict";
44

55
const ValidatorFuncs = {
@@ -14,13 +14,9 @@
1414
url: (val) => G.safeParse(G.url(), val).ok,
1515
date: (val, format, locale) => {
1616
try {
17-
if (!format) {
18-
datetime(val);
19-
} else {
20-
Datetime.from(val, format, locale);
21-
}
22-
return true;
23-
} catch (e) {
17+
const _d = !format ? datetime(val) : Datetime.from(val, format, locale);
18+
return !format ? true : _d.format(format, locale) === val;
19+
} catch {
2420
return false;
2521
}
2622
},
@@ -35,9 +31,9 @@
3531
return Farbe.Palette.color(val, Farbe.StandardColors) || Farbe.Routines.isColor(val);
3632
},
3733
pattern: (val, pat) => G.safeParse(G.pattern(pat), val).ok,
38-
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
34+
// biome-ignore lint/suspicious/noDoubleEquals: required for compare
3935
compare: (val, val2) => val == val2,
40-
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
36+
// biome-ignore lint/suspicious/noDoubleEquals: required for compare
4137
not: (val, not_this) => val != not_this,
4238
notequals: (val, val2) => val !== val2,
4339
equals: (val, val2) => val === val2,

0 commit comments

Comments
 (0)