diff --git a/index.js b/index.js
index a7ff51d..3f20187 100644
--- a/index.js
+++ b/index.js
@@ -27,9 +27,6 @@ module.exports = {
label: 'date',
placeholder: 'date',
type: 'date',
- settings: {
- empty: true,
- },
},
},
html: '',
diff --git a/lib/validation.js b/lib/validation.js
index 6362fe0..3f519ad 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -19,9 +19,11 @@
* @module dateValidation
*/
-module.exports = function dateValidation(input, settings) {
- if (input.target.value === '' && !settings.target.empty) {
- return `${input.target.name} cannot be left blank!`;
+const isDate = require('validator/lib/isDate');
+
+module.exports = function dateValidation(input) {
+ if (input.target.value && !isDate(input.target.value)) {
+ return `${input.target.name} must be a date!`;
}
return true;
diff --git a/package.json b/package.json
index 2b03242..cdccb18 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,9 @@
"Rachel White "
],
"license": "Apache-2",
- "dependencies": {},
+ "dependencies": {
+ "validator": "^5.7.0"
+ },
"devDependencies": {
"ava": "^0.14.0",
"coveralls": "^2.11.9",
diff --git a/tests/validation.js b/tests/validation.js
index 99b964c..3100fe2 100644
--- a/tests/validation.js
+++ b/tests/validation.js
@@ -1,37 +1,38 @@
import test from 'ava';
import validation from '../lib/validation';
-const input = {
+const empty = {
target: {
- name: 'date',
- value: 'foo bar baz',
- },
- all: {
- date: 'foo bar baz',
+ name: 'empty',
+ value: '',
},
};
-const settings = {
+const input = {
target: {
- empty: false,
+ name: 'good',
+ value: '1972-08-21',
},
- all: {
- date: {
- empty: false,
- },
+};
+
+const bad = {
+ target: {
+ name: 'bad',
+ value: '1972-08-foo',
},
};
+// Empty input
+test('empty input', t => {
+ t.true(validation(empty), 'Empty input returns true');
+});
// Valid input
test('valid input', t => {
- t.true(validation(input, settings), 'Valid input returns true');
+ t.true(validation(input), 'Valid input returns true');
});
-// Invalid input
-test('validate correct input', t => {
- const ip = input;
- ip.target.value = '';
-
- t.is(validation(ip, settings), 'date cannot be left blank!', 'Return string if not valid');
+// Valid input
+test('bad input', t => {
+ t.is(validation(bad), 'bad must be a date!', 'Bad input returns true');
});