Skip to content

Commit 3b90484

Browse files
authored
Merge pull request #47 from scottnath/hotfix/val
remove old validation
2 parents 1aea474 + 29e1a01 commit 3b90484

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ module.exports = {
2727
label: 'date',
2828
placeholder: 'date',
2929
type: 'date',
30-
settings: {
31-
empty: true,
32-
},
3330
},
3431
},
3532
html: '<label for="{{date.id}}">{{date.label}}</label><input type="{{date.type}}" id="{{date.id}}" name="{{date.name}}" value="{{date.value}}" placeholder="{{date.placeholder}}" />',

lib/validation.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
* @module dateValidation
2020
*/
2121

22-
module.exports = function dateValidation(input, settings) {
23-
if (input.target.value === '' && !settings.target.empty) {
24-
return `${input.target.name} cannot be left blank!`;
22+
const isDate = require('validator/lib/isDate');
23+
24+
module.exports = function dateValidation(input) {
25+
if (input.target.value && !isDate(input.target.value)) {
26+
return `${input.target.name} must be a date!`;
2527
}
2628

2729
return true;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"Rachel White <[email protected]>"
2222
],
2323
"license": "Apache-2",
24-
"dependencies": {},
24+
"dependencies": {
25+
"validator": "^5.7.0"
26+
},
2527
"devDependencies": {
2628
"ava": "^0.14.0",
2729
"coveralls": "^2.11.9",

tests/validation.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
import test from 'ava';
22
import validation from '../lib/validation';
33

4-
const input = {
4+
const empty = {
55
target: {
6-
name: 'date',
7-
value: 'foo bar baz',
8-
},
9-
all: {
10-
date: 'foo bar baz',
6+
name: 'empty',
7+
value: '',
118
},
129
};
1310

14-
const settings = {
11+
const input = {
1512
target: {
16-
empty: false,
13+
name: 'good',
14+
value: '1972-08-21',
1715
},
18-
all: {
19-
date: {
20-
empty: false,
21-
},
16+
};
17+
18+
const bad = {
19+
target: {
20+
name: 'bad',
21+
value: '1972-08-foo',
2222
},
2323
};
2424

25+
// Empty input
26+
test('empty input', t => {
27+
t.true(validation(empty), 'Empty input returns true');
28+
});
2529

2630
// Valid input
2731
test('valid input', t => {
28-
t.true(validation(input, settings), 'Valid input returns true');
32+
t.true(validation(input), 'Valid input returns true');
2933
});
3034

31-
// Invalid input
32-
test('validate correct input', t => {
33-
const ip = input;
34-
ip.target.value = '';
35-
36-
t.is(validation(ip, settings), 'date cannot be left blank!', 'Return string if not valid');
35+
// Valid input
36+
test('bad input', t => {
37+
t.is(validation(bad), 'bad must be a date!', 'Bad input returns true');
3738
});

0 commit comments

Comments
 (0)