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

Commit

Permalink
If translation isn't working, throw an error
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Sep 1, 2016
1 parent 72f62bf commit ba2ba9a
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.4",
"version": "1.5.5",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down Expand Up @@ -47,4 +47,4 @@
"devDependencies": {
"angular-route": ">= 1.2.0"
}
}
}
6 changes: 3 additions & 3 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions more-examples/customRemote/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ myApp.controller('CtrlService', ['$scope', '$q', 'ValidationService', function (
var vs = new ValidationService({ controllerAs: vms, debounce: 500 });

vs.setGlobalOptions({ scope: $scope })
.addValidator('input3', 'alpha|min_len:2|remote:vms.myRemoteValidation3():alt=Alternate error message.|required')
.addValidator('input3', 'alpha|min_len:2|remote:vms.myRemoteValidation3:alt=Alternate error message.|required')
.addValidator('input4', 'alpha|min_len:2|remote:vms.myRemoteValidation4()|required');

vms.myRemoteValidation3 = function() {
var deferred = $q.defer();
setTimeout(function() {
var isValid = (vms.model.input3 === "abc") ? true : false;
deferred.resolve({ isValid: isValid, message: 'Returned error from promise.'});
}, 500);
}, 100);

return deferred.promise;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.4",
"version": "1.5.5",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
3 changes: 3 additions & 0 deletions protractor/angularUI_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
it('Should enter valid date expect no errors on input and validation summary', function () {
var elmInput = $('[name=dateOfChange]');
elmInput.sendKeys(validDate);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// validation summary should become empty
Expand All @@ -30,6 +31,7 @@
it('Should enter outside of range date and show dateOfChange error on input and ValidationSummary', function () {
var elmInput = $('[name=dateOfChange]');
elmInput.sendKeys(invalidOverDate);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var itemRows = element.all(by.binding('message'));
Expand All @@ -43,6 +45,7 @@
it('Should enter wrong date format and show dateOfChange error on input and ValidationSummary', function () {
var elmInput = $('[name=dateOfChange]');
elmInput.sendKeys(invalidTypoDate);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var itemRows = element.all(by.binding('message'));
Expand Down
2 changes: 2 additions & 0 deletions protractor/badInput_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Angular-Validation badInput Tests:', function () {
it('Should display same invalid character error message even after a Tab', function() {
// make input3 invalid, remove text
var elmInput2 = $('[name=input2]');
element(by.css('body')).click();
elmInput2.sendKeys(protractor.Key.TAB);

// error should appear on input2
Expand Down Expand Up @@ -95,6 +96,7 @@ describe('Angular-Validation badInput Tests:', function () {
var elmInput2 = $('[name=input2]');
elmInput2.click();
clearInput(elmInput2, 5);
element(by.css('body')).click();
elmInput2.sendKeys(protractor.Key.TAB);

// error should appear on input2
Expand Down
1 change: 1 addition & 0 deletions protractor/callback_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Angular-Validation callback Validation Tests:', function () {
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down
2 changes: 1 addition & 1 deletion protractor/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'browserName': 'chrome',
'chromeOptions': {
// get rid of --ignore-certificate yellow warning
args: ['--no-sandbox', 'test-type=browser'],
args: ['--no-sandbox', 'test-type=browser', 'disable-extensions'],
// set download path and avoid prompting for download even though
// even though this is already the default Chrome but for completeness
prefs: {
Expand Down
3 changes: 3 additions & 0 deletions protractor/controllerAsWithRoute_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
it('Should enter valid data and show 0 error on Top Form Valdation Summary', function () {
var elmInput = $('[name=f1]');
elmInput.sendKeys('abc');
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// validation summary should become empty
Expand All @@ -36,6 +37,7 @@
it('Should enter valid data and show 0 error on bottom Form Valdation Summary in ngView (First Route)', function () {
var elmInput = $('[name=firstField]');
elmInput.sendKeys('abc');
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// validation summary should become empty
Expand Down Expand Up @@ -63,6 +65,7 @@
it('Should enter valid data and show 0 error on bottom Form Valdation Summary in ngView (First Route)', function () {
var elmInput = $('[name=secondField]');
elmInput.sendKeys('abc');
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// validation summary should become empty
Expand Down
3 changes: 3 additions & 0 deletions protractor/custom_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand All @@ -74,6 +75,7 @@
elmInput.click();
clearInput(elmInput);
elmInput.sendKeys(validInputTexts[i]);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down Expand Up @@ -114,6 +116,7 @@
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down
4 changes: 4 additions & 0 deletions protractor/dynamic_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
it('Should enter valid data in Form1 and expect valid Form1 but invalid Form2', function () {
var elmFirstName = $('[name=firstName]');
elmFirstName.sendKeys('abc');
element(by.css('body')).click();
elmFirstName.sendKeys(protractor.Key.TAB);

var elmLastName = $('[name=lastName]');
elmLastName.sendKeys('def');
element(by.css('body')).click();
elmLastName.sendKeys(protractor.Key.TAB);

var validateBtn = $('[name=validateForms]');
Expand All @@ -54,10 +56,12 @@
it('Should enter valid data in Form2 and expect both Forms to be valid', function () {
var elmEmail = $('[name=email]');
elmEmail.sendKeys('abc');
element(by.css('body')).click();
elmEmail.sendKeys(protractor.Key.TAB);

var elmPhone = $('[name=phoneNo]');
elmPhone.sendKeys('def');
element(by.css('body')).click();
elmPhone.sendKeys(protractor.Key.TAB);

var validateBtn = $('[name=validateForms]');
Expand Down
3 changes: 3 additions & 0 deletions protractor/full_tests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
for (var i = 0, ln = validations.length; i < ln; i++) {
var elmInput = $('[name=input' + i + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input' + i + ']').click();

Expand All @@ -73,6 +74,7 @@
(function(elmInput, data, i) {
elmInput.clear().then(function() {
elmInput.sendKeys(data);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input' + i + ']').click();
var elmError = $('.validation-input' + i);
Expand Down Expand Up @@ -100,6 +102,7 @@
(function(elmInput, data, i) {
elmInput.clear().then(function() {
elmInput.sendKeys(data);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input' + i + ']').click();
var elmError = $('.validation-input' + i);
Expand Down
1 change: 1 addition & 0 deletions protractor/interpolate_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
it('Should enter valid data and show 0 error on bottom Form in ngView (First Route)', function () {
var elmInput = $('[name=if1]');
elmInput.sendKeys('abc');
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// validation summary should become empty
Expand Down
14 changes: 14 additions & 0 deletions protractor/mixed_validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
it('Should click, blur on Remote input and error message should display', function () {
var elmInput = $('[name=input1]');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input1]').click();
browser.waitForAngular();
Expand All @@ -143,6 +144,7 @@
var elmInput = $('[name=input1]');
elmInput.click();
elmInput.sendKeys('ab');
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input1]').click();
browser.sleep(1100); // sleep because of our data sample having a delay of 1sec internally, we use 1.5sec on this side to be sure
Expand All @@ -155,6 +157,7 @@
var elmInput = $('[name=input1]');
elmInput.clear().then(function() {
elmInput.sendKeys('abc');
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input1]').click();
browser.sleep(1100); // sleep because of our data sample having a delay of 1sec internally, we use 1.5sec on this side to be sure
Expand All @@ -172,12 +175,14 @@
}
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=' + formElementNames[i] + ']').click(); // click on label to blur away

if (formElementNames[i] === 'select1') {
element(by.cssContainingText('option', 'en')).click(); // click on good option first
element(by.cssContainingText('option', '...')).click(); // then click on option[0], the one containing '...'
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-select1');
Expand All @@ -191,6 +196,7 @@
});

it('Should enter valid text and make error go away', function () {
browser.sleep(2000);
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
// some fields are not required or disabled so no error will show up, continue to next ones
if (formElementNames[i] === 'input12' || formElementNames[i] === 'input14') {
Expand All @@ -200,11 +206,13 @@
elmInput.click();
elmInput.sendKeys(validInputTexts[i]);
elmInput.sendKeys(protractor.Key.TAB);
element(by.css('body')).click();
//$('[for=' + formElementNames[i] + ']').click(); // click on label to blur away

if (formElementNames[i] === 'select1') {
element(by.cssContainingText('option', validInputTexts[i])).click(); // click on good option
elmInput.sendKeys(protractor.Key.TAB);
element(by.css('body')).click();
}

var elmError = $('.validation-' + formElementNames[i]);
Expand All @@ -223,6 +231,7 @@
// make input3 invalid, remove text
var elmInput3 = $('[name=input3]');
clearInput(elmInput3);
element(by.css('body')).click();
elmInput3.sendKeys(protractor.Key.TAB);
//$('[for=input3]').click(); // click on label to blur away

Expand Down Expand Up @@ -306,6 +315,7 @@
it('Should focus and blur out of input22 & error should appear', function() {
var elmInput = $('[name=input22]');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
//$('[for=input22]').click(); // click on label to blur away

Expand Down Expand Up @@ -393,10 +403,12 @@
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
elmInput.sendKeys(validInputTexts[i]);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

if (formElementNames[i] === 'select1') {
element(by.cssContainingText('option', validInputTexts[i])).click(); // click on good option
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
}

Expand Down Expand Up @@ -506,6 +518,7 @@

if (formElement2FormsNames[i] === 'select1') {
element(by.cssContainingText('option', validInput2FormsTexts[i])).click(); // click on good option
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);
}

Expand Down Expand Up @@ -587,6 +600,7 @@
var elmInput = $('[name=' + formElement2FormsNames[i] + ']');
elmInput.click();
elmInput.sendKeys("a");
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// both inputs should have the same error message
Expand Down
3 changes: 3 additions & 0 deletions protractor/remote_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand All @@ -68,6 +69,7 @@
clearInput(elmInput);
elmInput.sendKeys(validInputTexts[i]);
elmInput.sendKeys(protractor.Key.TAB);
element(by.css('body')).click();
browser.sleep(1000);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down Expand Up @@ -108,6 +110,7 @@
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down
2 changes: 2 additions & 0 deletions protractor/thirdParty_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
elmInput.click();
elmInput.sendKeys('tag4');
elmInput.sendKeys(protractor.Key.ENTER);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-input1');
Expand All @@ -92,6 +93,7 @@
elmInput.click();
elmInput.sendKeys('xyz');
elmInput.sendKeys(protractor.Key.ENTER);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

// get 2 errors concatenated
Expand Down
4 changes: 4 additions & 0 deletions protractor/validRequireHowMany_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('Angular-Validation ValidRequireHowMany Validation Tests:', function ()
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand All @@ -51,6 +52,7 @@ describe('Angular-Validation ValidRequireHowMany Validation Tests:', function ()
elmInput.click();
clearInput(elmInput);
elmInput.sendKeys(invalidInputTexts[i]);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand All @@ -64,6 +66,7 @@ describe('Angular-Validation ValidRequireHowMany Validation Tests:', function ()
elmInput.click();
clearInput(elmInput);
elmInput.sendKeys(validInputTexts[i]);
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down Expand Up @@ -104,6 +107,7 @@ describe('Angular-Validation ValidRequireHowMany Validation Tests:', function ()
for (var i = 0, ln = formElementNames.length; i < ln; i++) {
var elmInput = $('[name=' + formElementNames[i] + ']');
elmInput.click();
element(by.css('body')).click();
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.5.4`
`Version: 1.5.5`
### Forms Validation with Angular made easy!
##### (Concept comes from the amazing Laravel)

Expand Down
2 changes: 2 additions & 0 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ angular
validationElmObj.message += errorMessageSeparator + msgToTranslate;
}
addToValidationAndDisplayError(self, formElmObj, validationElmObj.message, isFieldValid, showError);
} else {
throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.", data);
}
});
})(formElmObj, isConditionValid, validator);
Expand Down

0 comments on commit ba2ba9a

Please sign in to comment.