Skip to content

Commit 430a1e2

Browse files
author
Perepecho Georgy
committed
bump v1.4.0
1 parent ba8ae50 commit 430a1e2

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ The following example will only validate input of a field if it is "hi"
139139

140140
```js
141141
function: (name, value) => {
142-
if(name == 'hi'){
142+
if (name === 'hi') {
143143
return true;
144-
}else{
144+
} else {
145145
return false;
146146
};
147147
}
@@ -380,6 +380,8 @@ Added rule for check strength of password (default and custom)
380380
Added tooltip style error
381381
### 1.3.0
382382
Added feature for check required radio buttons
383+
### 1.4.0
384+
Added feature to allow the user to provide their own validation function
383385
384386
## Contributing
385387
* Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found.

dist/js/just-validate.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
275275
RULE_ZIP = 'zip',
276276
RULE_PHONE = 'phone',
277277
RULE_REMOTE = 'remote',
278-
RULE_STRENGTH = 'strength';
278+
RULE_STRENGTH = 'strength',
279+
RULE_FUNCTION = 'function';
279280

280281
var formatParams = function formatParams(params, method) {
281282
if (typeof params === 'string') {
@@ -399,7 +400,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
399400
minLength: 'The field must contain a minimum of :value characters',
400401
password: 'Password is not valid',
401402
remote: 'Email already exists',
402-
strength: 'Password must contents at least one uppercase letter, one lowercase letter and one number'
403+
strength: 'Password must contents at least one uppercase letter, one lowercase letter and one number',
404+
function: 'Function returned false'
403405
},
404406
/**
405407
* Keyup handler
@@ -791,10 +793,21 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
791793
for (var rule in rules) {
792794
var ruleValue = rules[rule];
793795

794-
if (rule !== RULE_REQUIRED && value == '') {
796+
if (rule !== RULE_REQUIRED && rule !== RULE_FUNCTION && value == '') {
795797
return;
796798
}
797799
switch (rule) {
800+
case RULE_FUNCTION:
801+
{
802+
if (typeof ruleValue !== 'function') {
803+
break;
804+
}
805+
if (ruleValue(name, value)) {
806+
break;
807+
}
808+
this.generateMessage(RULE_FUNCTION, name, ruleValue);
809+
return;
810+
}
798811
case RULE_REQUIRED:
799812
{
800813
if (!ruleValue) {
@@ -1054,7 +1067,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
10541067
$elems[i].style.filter = '';
10551068
}
10561069
}
1057-
10581070
};
10591071

10601072
window.JustValidate = JustValidate;

0 commit comments

Comments
 (0)