Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 9c89eb9

Browse files
committed
Enhancement #34 to add Remote Validation
- Enhancement #34 to add Remote Validation - Updated Protractor to cover this new Remote Validation
1 parent 15b11e6 commit 9c89eb9

18 files changed

+306
-317
lines changed

app.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ myApp.controller('Ctrl', ['$location', '$route', '$scope', '$translate', functio
3737

3838
// -- Controller to use Angular-Validation Directive
3939
// -----------------------------------------------
40-
myApp.controller('CtrlValidationDirective', ['$scope', 'validationService', function ($scope, validationService) {
40+
myApp.controller('CtrlValidationDirective', ['$q', '$scope', 'validationService', function ($q, $scope, validationService) {
4141
$scope.$validationOptions = { debounce: 1500 }; // you can change default debounce globally
4242

4343
$scope.submitForm = function() {
@@ -48,6 +48,20 @@ myApp.controller('CtrlValidationDirective', ['$scope', 'validationService', func
4848
$scope.showValidationSummary = function () {
4949
$scope.displayValidationSummary = true;
5050
}
51+
$scope.customRemoteValidationCall = function() {
52+
var deferred = $q.defer();
53+
setTimeout(function() {
54+
var isValid = ($scope.input1 === "abc") ? true : false;
55+
56+
// you can return a boolean for isValid
57+
//deferred.resolve(isValid);
58+
59+
// or you can return an object as { isValid: bool, message: msg }
60+
deferred.resolve({ isValid: isValid, message: 'Returned error from promise.'});
61+
}, 1000);
62+
63+
return deferred.promise;
64+
}
5165
}]);
5266

5367
// -- Controller to use Angular-Validation Directive with 2 forms
@@ -67,18 +81,18 @@ myApp.controller('Ctrl2forms', ['$scope', 'validationService', function ($scope,
6781
// -----------------------------------------------
6882

6983
// exact same testing form used except that all validators are programmatically added inside controller via Angular-Validation Service
70-
myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationService', function ($scope, $translate, validationService) {
84+
myApp.controller('CtrlValidationService', ['$q', '$scope', '$translate', 'validationService', function ($q, $scope, $translate, validationService) {
7185
// start by creating the service
7286
var myValidation = new validationService();
7387

7488
// you can create indepent call to the validation service
7589
// also below the multiple properties available
7690
myValidation.addValidator({
77-
elmName: 'input2',
91+
elmName: 'input1',
7892
// friendlyName: $translate.instant('FIRST_NAME'),
79-
debounce: 3000,
93+
debounce: 1000,
8094
scope: $scope,
81-
rules: 'numeric_signed|required'
95+
rules: 'alpha|min_len:2|remote:customRemoteValidationCall|required'
8296
});
8397

8498
// you can also chain validation service and add multiple validators at once
@@ -90,6 +104,7 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
90104
// the available object properties are the exact same set as the directive except that they are camelCase
91105
myValidation
92106
.setGlobalOptions({ debounce: 1500, scope: $scope })
107+
.addValidator({ elmName: 'input2', debounce: 3000, rules: 'numeric_signed|required'})
93108
.addValidator('input3', 'float_signed|between_num:-0.6,99.5|required')
94109
.addValidator('input4', 'exact_len:4|regex:YYWW:=^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$:regex|required|integer')
95110
.addValidator('input5', 'email|required|min_len:6', $translate.instant('INPUT5')) // 3rd argument being the Friendly name
@@ -125,6 +140,15 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
125140
alert('All good, proceed with submit...');
126141
}
127142
}
143+
$scope.customRemoteValidationCall = function() {
144+
var deferred = $q.defer();
145+
setTimeout(function() {
146+
var isValid = ($scope.input1 === "abc") ? true : false;
147+
deferred.resolve({ isValid: isValid, message: 'Returned error from promise.'});
148+
}, 1000);
149+
150+
return deferred.promise;
151+
}
128152
}]);
129153

130154
// -- Controller to use Angular-Validation with Directive and ngRepeat

bower.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.3.24",
3+
"version": "1.3.25",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": [
@@ -18,11 +18,13 @@
1818
"license": "MIT",
1919
"ignore": [
2020
"**/.*",
21+
"full-tests",
2122
"node_modules",
2223
"bower_components",
2324
"test",
2425
"tests",
2526
"more-examples",
27+
"protractor",
2628
"templates",
2729
"app.js",
2830
"changelog.txt",

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ Angular-Validation change logs
2525
1.3.21 (2015-04-29) Moved the Alternate Text inside the $translate promise as well which removes possible delay of non-translated text appearing as alternate text (this will not affect regular text, or already translated text). Also cleanup code and made my Gulp task even more automated.
2626
1.3.22 (2015-05-03) Added new element attribute of `friendly-name` which is used ONLY in the ValidationSummary, this friendly name is to give a better element name display, which also support translation, inside the ValidationSummary instead of just "input1" (see ValidationSummary for more details).
2727
1.3.23 (2015-05-05) Added option to display only last error message instead of all messages at once. Fixed a bug where changing route on View/Controller would make the ValidationSummary fail when coming back to original View/Controller, this bug was associated to the fact that the ValidationSummary kept growing from Controller to Controller, now this ValidationSummary is wipe out as soon as we detect a route change.
28-
1.3.24 (2015-05-17) Replaced all `:param` inside each locale translations with a better standard of {0}, {1}, etc.. like C# `String.Format()`. Added a full Protractor End-to-End test suite (1000+ asserts). Fixed a few minor bugs found with Protractor test cases. Fixed issue #36, bower.json scripts in wrong order.
28+
1.3.24 (2015-05-17) Replaced all `:param` inside each locale translations with a better standard of {0}, {1}, etc.. like C# `String.Format()`. Added a full Protractor End-to-End test suite (1000+ asserts). Fixed a few minor bugs found with Protractor test cases. Fixed issue #36, bower.json scripts in wrong order.
29+
1.3.25 (2015-05-19) Enhancement #34 to add Remote Validation and updated Protractor to cover this new feature.

dist/angular-validation.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
2626

2727
<span class="text-info" style="margin-left: 20px"><strong>Type: </strong></span>
2828
<div class="btn-group btn-group-sm">
29-
<button type="button" name="btn_goto_directive" class="btn btn-default" ng-click="goto('/validate-directive')">Directive</button>
30-
<button type="button" name="btn_goto_service" class="btn btn-default" ng-click="goto('/validate-service')">Service</button>
29+
<button type="button" name="btn_goto_Directive" class="btn btn-default" ng-click="goto('/validate-directive')">Directive</button>
30+
<button type="button" name="btn_goto_Service" class="btn btn-default" ng-click="goto('/validate-service')">Service</button>
3131
<button type="button" name="btn_goto_2forms" class="btn btn-default" ng-click="goto('/validate-2forms')">2 Forms</button>
3232
<button type="button" name="btn_goto_ngrepeat" class="btn btn-default" ng-click="goto('/validate-ngRepeat')">ngRepeat</button>
3333
</div>

locales/validation/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"AREA1": "TextArea: Alphanumeric + Minimum(15) + Required",
5757
"ERRORS": "Errors",
5858
"CHANGE_LANGUAGE": "Change language",
59+
"INPUT1": "Remote validation - Type \"abc\" for a valid answer ",
5960
"INPUT2": "Number positive or negative -- input type=\"number\" -- Error on non-numeric characters ",
6061
"INPUT3": "Floating number range (integer excluded) -- between_num:x,y OR min_num:x|max_num:y ",
6162
"INPUT4": "Multiple Validations + Custom Regex of Date Code (YYWW)",

locales/validation/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"AREA1": "Area de texto: Alfanúmerica + Minimo(15) + Requerido",
5757
"ERRORS": "Errores",
5858
"CHANGE_LANGUAGE": "Cambiar idioma",
59+
"INPUT1": "Validación Remota - Escriba \"abc\" para una respuesta válida ",
5960
"INPUT2": "Número positivo o negativo -- input type=\"number\" -- Error o caracteres no númericos ",
6061
"INPUT3": "Rango decimal (Los números enteros no son validos) -- between_num:x,y ó min_num:x|max_num:y ",
6162
"INPUT4": "Multiples validaciones + Código de fecha personalizado (YYWW)",

locales/validation/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"AREA1": "TextArea: Alphanumérique + Minimum(15) + Required",
5757
"ERRORS": "Erreurs",
5858
"CHANGE_LANGUAGE": "Changer de langue",
59+
"INPUT1": "Validation à Distance - Taper \"abc\" pour une réponse valide ",
5960
"INPUT2": "Nombre positif ou négatif -- input type=\"number\" -- Erreur sur caractères non-numérique",
6061
"INPUT3": "Intervalle de Nombre Flottant (entier exclu) -- between_num:x,y OU min_num:x|max_num:y",
6162
"INPUT4": "Multiple Validations + Regex Personnalisé d'un Code Date (AASS)",

locales/validation/no.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"AREA1": "TextArea: Alfanumerisk + Minimum(15) + Påkrevd",
5757
"ERRORS": "Feil",
5858
"CHANGE_LANGUAGE": "Endre språk.",
59+
"INPUT1": "Ekstern Validering - Type \"abc\" for et gyldig svar ",
5960
"INPUT2": "Positivt eller negativt nummer -- input type=\"number\" -- Feil på ikke-numeriske tegn ",
6061
"INPUT3": "Flyttalssutvalg (heltall ekskludert) -- between_num:x,y eller min_num:x|max_num:y ",
6162
"INPUT4": "Multiple Valideringer + Tilpasset Regex av dato kode (YYWW)",

locales/validation/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"AREA1": "TextArea: Буквенно-цифровой + Минимум(15) + Обязательно + Обязательно для заполнения",
5757
"ERRORS": "Ошибки",
5858
"CHANGE_LANGUAGE": "Изменить язык",
59+
"INPUT1": "дистанционное проверки - введите \"abc\" для действительного ответа ",
5960
"INPUT2": "Число положительное или отрицательное -- input type=\"number\" -- Ошибка на не числовых значениях ",
6061
"INPUT3": "Диапазон дробного числа (включая целые) -- between_num:x,y или min_num:x|max_num:y ",
6162
"INPUT4": "Множественная проверка + Пользовательское регулярное выражение формата даты (YYWW)",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.3.24",
3+
"version": "1.3.25",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "app.js",

protractor/full_tests_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105
}
106106
}, 420000);
107107

108-
}); // describe: When clicking on top menu ...
109-
})(types, k);
110-
} // for()
108+
}); // describe: When clicking on top menu ...
109+
})(types, k); // closure
110+
} // for()
111111

112112
});
113113

0 commit comments

Comments
 (0)