Skip to content

Commit db4ea23

Browse files
committed
Merge pull request victorjonsson#42 from stevewasiura/patch-10
add validator checkbox_group, plus utility for numeric range
2 parents 8fe5113 + 6400635 commit db4ea23

File tree

2 files changed

+179
-68
lines changed

2 files changed

+179
-68
lines changed

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ So what has changed since version 1.x?
6161
* **length***min/max/range*
6262
* **required***no validation except that a value has to be given*
6363
* **custom***Validate value against regexp*
64+
* **checkboxgroup***ensure at least 1 checkbox in group has been selected*
6465
* Show help information automatically when input is focused
6566
* Validate given values immediately when input looses focus.
6667
* Make validation optional by adding attribute data-validation-optional="true" to the element. This means
@@ -135,7 +136,7 @@ that checks if the input contains an even number.
135136
// Add validator
136137
$.formUtils.addValidator({
137138
name : 'even',
138-
validate : function(value, $el, config, language, $form) {
139+
validatorFunction : function(value, $el, config, language, $form) {
139140
return parseInt(value, 10) % 2 === 0;
140141
},
141142
errorMessage : 'You have to answer an even number',
@@ -152,7 +153,7 @@ that checks if the input contains an even number.
152153

153154
*name* - The name of the validator, which is used in the validation attribute of the input element.
154155

155-
*validate* - Callback function that validates the input. Should return a boolean telling if the value is considered valid or not.
156+
*validatorFunction* - Callback function that validates the input. Should return a boolean telling if the value is considered valid or not.
156157

157158
*errorMessageKey* - Name of language property that is used in case the value of the input is invalid.
158159

@@ -228,11 +229,10 @@ var enErrorDialogs = {
228229
badTelephone : 'You have not given a correct phone number',
229230
badSecurityAnswer : 'You have not given a correct answer to the security question',
230231
badDate : 'You have not given a correct date',
231-
tooLongStart : 'You have given an answer longer than ',
232-
tooLongEnd : ' characters',
233-
tooShortStart : 'You have given an answer shorter than ',
234-
tooShortEnd : ' characters',
235-
badLength : 'You have to give an answer between ',
232+
lengthBadStart : 'You must give an answer between ',
233+
lengthBadEnd : 'characters',
234+
lengthTooLongStart : 'You have given an answer longer than ',
235+
lengthTooShortStart : 'You have given an answer shorter than ',
236236
notConfirmed : 'Values could not be confirmed',
237237
badDomain : 'Incorrect domain value',
238238
badUrl : 'The answer you gave was not a correct URL',
@@ -246,7 +246,14 @@ var enErrorDialogs = {
246246
badAlphaNumeric : 'The answer you gave must contain only alphanumeric characters ',
247247
badAlphaNumericExtra: ' and ',
248248
wrongFileSize : 'The file you are trying to upload is too large',
249-
wrongFileType : 'The file you are trying to upload is of wrong type'
249+
wrongFileType : 'The file you are trying to upload is of wrong type',
250+
groupCheckedTooFewStart : 'Please choose at least ',
251+
groupCheckedTooManyStart : 'Please choose a maximum of ',
252+
groupCheckedRangeStart : 'Please choose between ',
253+
groupCheckedEnd : ' item(s)',
254+
255+
_dummy--last-item-no-comma : 0
256+
250257
};
251258
```
252259

@@ -279,6 +286,17 @@ that attribute will be displayed instead of the error dialog that the validation
279286
</script>
280287
```
281288

289+
## Program Flow
290+
form submit() event is bound to jQ func **validateForm()**
291+
292+
when the form is submitted, it calls jQ func **$.formUtils.validateInput**, which calls **validatorFunction** for the specific validation rule assigned to the input element
293+
294+
if a validation fails, error messages are assigned and displayed as configured.
295+
296+
297+
if **validateOnBlur** = true, jQ finds all form input elements with the data-validation attribute and binds their onBlur event to call the function **validateInputOnBlur**. it calls jQ func **$.formUtils.validateInput** to validate the single input when blurred
298+
299+
282300
## Changelog
283301

284302
#### 2.0.7
@@ -303,7 +321,7 @@ that attribute will be displayed instead of the error dialog that the validation
303321

304322
#### Contributors
305323
<a href="https://github.com/robamaton" target="_blank">Joel Sutherland</a><br />
306-
<a href="https://github.com/stevewasiura" target="_blank">Steve Wasiura</a><br />
324+
<a href="http://stevewasiura.waztech.com" target="_blank">Steve Wasiura</a><br />
307325
<a href="https://github.com/mattclements" target="_blank">Matt Clements</a><br />
308326
<a href="https://github.com/dfcplc" target="_blank">@dfcplc</a><br />
309327
<a href="https://github.com/coffein" target="_blank">Andree Wendel</a><br />
@@ -317,3 +335,4 @@ that attribute will be displayed instead of the error dialog that the validation
317335

318336
<a href="http://projects.scottsplayground.com/iri/" target="_blank">Scott Gonzales</a> (URL regexp)<br />
319337
<a href="http://www.mypocket-technologies.com" target="_blank">Darren Mason</a> (Password strength meter)
338+
<a href="http://stevewasiura.waztech.com" target="_blank">Steve Wasiura</a> (Checkbox group)

0 commit comments

Comments
 (0)