Skip to content
This repository was archived by the owner on Aug 15, 2021. It is now read-only.

Commit 0488392

Browse files
committed
Fixed problem with the de-bounce function in the ngModel decorator.Option added to the validator service to automatically scroll to the first invalid input.
1 parent a894793 commit 0488392

8 files changed

+88
-40
lines changed

.jshintrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"describe": true,
2929
"expect": true,
3030
"it": true,
31-
"should": true
31+
"should": true,
32+
"clearTimeout": true,
33+
"setTimeout": true
3234
}
3335
}

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-auto-validate",
3-
"version": "1.19.0",
3+
"version": "1.19.1",
44
"description": "An automatic validation module for AngularJS which gets rid of excess html in favour of dynamic element modification to notify the user of validation errors",
55
"main": "dist/jcs-auto-validate.js",
66
"keywords": [

dist/changelog.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.19.1 16/11/2015
2+
Fixed problem with the de-bounce function in the ngModel decorator.
3+
Option added to the validator service to automatically scroll to the first invalid input.
4+
15
v1.19.0 25/10/2015
26
Possible breaking change fixing i18n caching issue with en-us and en-gb files. The default language
37
is now 'default' and not en-gb.

dist/jcs-auto-validate.js

+47-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* angular-auto-validate - v1.19.0 - 2015-10-25
2+
* angular-auto-validate - v1.19.1 - 2015-11-16
33
* https://github.com/jonsamwell/angular-auto-validate
44
* Copyright (c) 2015 Jon Samwell (http://www.jonsamwell.com)
55
*/
@@ -12,6 +12,7 @@ function ValidatorFn() {
1212
var elementStateModifiers = {},
1313
enableValidElementStyling = true,
1414
enableInvalidElementStyling = true,
15+
enableFirstInvalidElementScrollingOnSubmit = false,
1516
validationEnabled = true,
1617

1718
toBoolean = function (value) {
@@ -246,6 +247,25 @@ function ValidatorFn() {
246247
enableInvalidElementStyling = enabled;
247248
};
248249

250+
/**
251+
* @ngdoc function
252+
* @name validator#setFirstInvalidElementScrollingOnSubmit
253+
* @methodOf validator
254+
*
255+
* @description
256+
* Globally enables first invalid element scrolling on form submit. This is disabled by default.
257+
*
258+
* @param enabled {Boolean} enabled True to enable scrolling otherwise false.
259+
*/
260+
this.setFirstInvalidElementScrollingOnSubmit = function (enabled) {
261+
enableFirstInvalidElementScrollingOnSubmit = enabled;
262+
};
263+
264+
this.firstInvalidElementScrollingOnSubmitEnabled = function () {
265+
return enableFirstInvalidElementScrollingOnSubmit;
266+
};
267+
268+
249269
this.getDomModifier = function (el) {
250270
var modifierKey = (el !== undefined ? el.attr('element-modifier') : this.defaultElementModifier) ||
251271
(el !== undefined ? el.attr('data-element-modifier') : this.defaultElementModifier) ||
@@ -501,23 +521,24 @@ angular.module('jcs-autoValidate').factory('bootstrap3ElementModifier', Bootstra
501521
* Taken from https://github.com/angular/angular.js/issues/2690#issue-14462164 (with added tests of course!)
502522
*/
503523
function JCSDebounceFn($timeout) {
504-
var debounce = function (fn, timeout, apply) {
505-
timeout = angular.isUndefined(timeout) ? 0 : timeout;
506-
apply = angular.isUndefined(apply) ? true : apply; // !!default is true! most suitable to my experience
507-
var nthCall = 0;
508-
return function () { // intercepting fn
509-
var that = this;
510-
var argz = arguments;
511-
nthCall += 1;
512-
var later = (function (version) {
513-
return function () {
514-
if (version === nthCall) {
515-
return fn.apply(that, argz);
516-
}
517-
};
518-
})(nthCall);
524+
var debounce = function (func, wait, immediate) {
525+
var timeout;
526+
return function () {
527+
var context = this;
528+
var args = arguments;
529+
var later = function () {
530+
timeout = null;
531+
if (!immediate) {
532+
func.apply(context, args);
533+
}
534+
};
519535

520-
return $timeout(later, timeout, apply);
536+
var callNow = immediate && !timeout;
537+
$timeout.cancel(timeout);
538+
timeout = $timeout(later, wait, false);
539+
if (callNow) {
540+
func.apply(context, args);
541+
}
521542
};
522543
};
523544

@@ -830,7 +851,7 @@ function ElementUtilsFn() {
830851
};
831852
}
832853

833-
function ValidationManagerFn(validator, elementUtils) {
854+
function ValidationManagerFn(validator, elementUtils, $anchorScroll) {
834855
var elementTypesToValidate = ['input', 'textarea', 'select', 'form'],
835856

836857
elementIsVisible = function (el) {
@@ -984,6 +1005,12 @@ function ValidationManagerFn(validator, elementUtils) {
9841005
ctrlFormOptions.forceValidation = force;
9851006
try {
9861007
isValid = validateElement(controller, ctrlElement, ctrlFormOptions);
1008+
if (validator.firstInvalidElementScrollingOnSubmitEnabled() && !isValid && frmValid) {
1009+
var ctrlElementId = ctrlElement.attr('id');
1010+
if (ctrlElementId) {
1011+
$anchorScroll(ctrlElementId);
1012+
}
1013+
}
9871014
frmValid = frmValid && isValid;
9881015
} finally {
9891016
ctrlFormOptions.forceValidation = originalForceValue;
@@ -1045,7 +1072,8 @@ function ValidationManagerFn(validator, elementUtils) {
10451072

10461073
ValidationManagerFn.$inject = [
10471074
'validator',
1048-
'jcs-elementUtils'
1075+
'jcs-elementUtils',
1076+
'$anchorScroll'
10491077
];
10501078

10511079
angular.module('jcs-autoValidate').factory('jcs-elementUtils', ElementUtilsFn);

dist/jcs-auto-validate.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-auto-validate",
3-
"version": "1.19.0",
3+
"version": "1.19.1",
44
"description": "An automatic validation module for AngularJS which gets rid of excess html in favour of dynamic element modification to notify the user of validation errors",
55
"main": "angular-auto-validate.min.js",
66
"scripts": {

src/lang/jcs-auto-validate_tr-TR.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"defaultMsg": "Lütfen geçerli bir hata mesajı ekleyiniz {0}",
3+
"email": "Lütfen geçerli bir e-posta adresi giriniz",
4+
"minlength": "Lütfen en az {0} karakter giriniz",
5+
"maxlength": "Maksimum {0} karakterden fazla giriş yaptınız",
6+
"min": "Lütfen minimum {0} rakam griniz.",
7+
"max": "Lütfen maksimum {0} rakam giriniz",
8+
"required": "Bu alan zorunludur. Boş bırakılamaz",
9+
"date": "Lütfen geçerli bir tarih girin",
10+
"pattern": "Lütfen belirtilen {0} ifadeye uygun bir bilgi giriniz",
11+
"number": "Lütfen geçerli bir rakam giriniz",
12+
"url": "Lütfen geçerli bir URL giriniz. Örneğin: http(s)://www.google.com"
13+
}

src/services/debounce.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
* Taken from https://github.com/angular/angular.js/issues/2690#issue-14462164 (with added tests of course!)
33
*/
44
function JCSDebounceFn($timeout) {
5-
var debounce = function (fn, timeout, apply) {
6-
timeout = angular.isUndefined(timeout) ? 0 : timeout;
7-
apply = angular.isUndefined(apply) ? true : apply; // !!default is true! most suitable to my experience
8-
var nthCall = 0;
9-
return function () { // intercepting fn
10-
var that = this;
11-
var argz = arguments;
12-
nthCall += 1;
13-
var later = (function (version) {
14-
return function () {
15-
if (version === nthCall) {
16-
return fn.apply(that, argz);
17-
}
18-
};
19-
})(nthCall);
5+
var debounce = function (func, wait, immediate) {
6+
var timeout;
7+
return function () {
8+
var context = this;
9+
var args = arguments;
10+
var later = function () {
11+
timeout = null;
12+
if (!immediate) {
13+
func.apply(context, args);
14+
}
15+
};
2016

21-
return $timeout(later, timeout, apply);
17+
var callNow = immediate && !timeout;
18+
$timeout.cancel(timeout);
19+
timeout = $timeout(later, wait, false);
20+
if (callNow) {
21+
func.apply(context, args);
22+
}
2223
};
2324
};
2425

0 commit comments

Comments
 (0)