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

Commit

Permalink
Fixed an issue with 3rd party single object
Browse files Browse the repository at this point in the history
- Fixed an issue with 3rd validation when an object was disguised as an
array and was not triggering a $scope.$watch, so the validation was
never kicking in. For example the 3rd party package "Dropdown
Multiselect" when setting the option of "selectionLimit" to 1 is
returning an array while in fact it's a an object. It's returning this
`[id: 1, label: 'John']` but in reality this is an object (not an array)
and should be this `{id: 1, label: 'John'}` and so because of that, the
$scope.$watch never kicks in.
- Also added a international phone number validation
  • Loading branch information
ghiscoding committed Jul 29, 2016
1 parent 7389b4d commit 5696c3a
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.3",
"version": "1.5.4",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
8 changes: 4 additions & 4 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions locales/validation/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Ha de contenir un text amb el format: {0}. ",
"INVALID_PATTERN_DATA": "Ha de contenir un text amb el format {{data}}. ",
"INVALID_PHONE_US": "Ha de ser un número de telèfon vàlid i ha d'incloure el codi d'àrea. ",
"INVALID_PHONE_INTERNATIONAL": "Ha de ser un número de telèfon internacional vàlida. ",
"INVALID_REQUIRED": "Camp requerit. ",
"INVALID_URL": "Ha de contenir una adreça URL vàlida. ",
"INVALID_TIME": "Ha de tenir un format de temps vàlid (hh: mm) o (hh: mm: ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Must be following this format: {0}. ",
"INVALID_PATTERN_DATA": "Must be following this format {{data}}. ",
"INVALID_PHONE_US": "Must be a valid phone number and must include area code. ",
"INVALID_PHONE_INTERNATIONAL": "Must be a valid international phone number. ",
"INVALID_REQUIRED": "Field is required. ",
"INVALID_URL": "Must be a valid URL. ",
"INVALID_TIME": "Must be a valid time format (hh:mm) OR (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Debe contener un texto con el formato: {0}. ",
"INVALID_PATTERN_DATA": "Debe contener un texto con el formato {{data}}. ",
"INVALID_PHONE_US": "Debe ser un número de teléfono válido y debe incluir el código de área. ",
"INVALID_PHONE_INTERNATIONAL": "Debe ser un número de teléfono internacional válida. ",
"INVALID_REQUIRED": "Campo requerido. ",
"INVALID_URL": "Debe contener una dirección URL válida. ",
"INVALID_TIME": "Debe contener un formato de tiempo válido (hh:mm) ó (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Doit suivre le format: {0}. ",
"INVALID_PATTERN_DATA": "Doit suivre le format {{data}}. ",
"INVALID_PHONE_US": "Doit être un numéro de téléphone valide et doit inclure le code régional. ",
"INVALID_PHONE_INTERNATIONAL": "Doit être un numéro de téléphone international valide. ",
"INVALID_REQUIRED": "Le champ est requis. ",
"INVALID_URL": "Doit être un URL valide. ",
"INVALID_TIME": "Doit être un format de temps valide (hh:mm) OU (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Må være på følgende format: {0}. ",
"INVALID_PATTERN_DATA": "Må være på følgende format {{data}}. ",
"INVALID_PHONE_US": "Må være et gyldig telefonnummer og inkluderer retningsnummer. ",
"INVALID_PHONE_INTERNATIONAL": "Må være et gyldig internasjonalt telefonnummer. ",
"INVALID_REQUIRED": "Feltet er påkrevd. ",
"INVALID_URL": "Må være en gyldig URL. ",
"INVALID_TIME": "Må være et gyldig tidsformat (tt:mm) OR (tt:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Musi być zgodne z formatem: {0}. ",
"INVALID_PATTERN_DATA": "Musi być zgodne z formatem {{data}}. ",
"INVALID_PHONE_US": "Musi być prawidłowy numer telefonu i musi zawierać numer kierunkowy. ",
"INVALID_PHONE_INTERNATIONAL": "Musi być ważny międzynarodowy numer telefonu. ",
"INVALID_REQUIRED": "Pole jest wymagane. ",
"INVALID_URL": "Musi być poprawnym adresem URL. ",
"INVALID_TIME": "Musi być poprawną godziną w formacie (gg:mm) OR (gg:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Deve seguir o seguinte formato: {0}. ",
"INVALID_PATTERN_DATA": "Deve seguir o seguinte formato {{data}}. ",
"INVALID_PHONE_US": "Deve ser um número de telefone válido e incluir o código de área. ",
"INVALID_PHONE_INTERNATIONAL": "Deve ser um número de telefone internacional válido. ",
"INVALID_REQUIRED": "Campo obrigatório. ",
"INVALID_URL": "Deve ser uma URL válida. ",
"INVALID_TIME": "Deve ser um formato de hora válido (hh:mm) ou (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"INVALID_PATTERN": "Должно соответствовать этому формату: {0}. ",
"INVALID_PATTERN_DATA": "Должно соответствовать этому формату {{data}}. ",
"INVALID_PHONE_US": "Должно быть допустимым номером телефона и должен включать в себя код города. ",
"INVALID_PHONE_INTERNATIONAL": "Должен быть действительным международный телефона номером. ",
"INVALID_REQUIRED": "Поле обязательно для заполнения. ",
"INVALID_URL": "Должно быть действительным URL адресом. ",
"INVALID_TIME": "Должно быть допустимым форматом времени (hh:mm) или (hh:mm:ss). ",
Expand Down
2 changes: 1 addition & 1 deletion more-examples/addon-3rdParty/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h4><strong>ERRORS!</strong></h4>
options="vm.select1data"
selected-model="vm.select1model"
ng-model="vm.select1model"
extra-settings="{externalIdProp: ''}"
extra-settings="{externalIdProp: '', selectionLimit: 1}"
validation="in_list:John,Jane|required" validation-array-objprop="label">
</div>
</div>
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.3",
"version": "1.5.4",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
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.3`
`Version: 1.5.4`
### Forms Validation with Angular made easy!
##### (Concept comes from the amazing Laravel)

Expand Down
13 changes: 12 additions & 1 deletion src/validation-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,21 @@
*/
function createWatch() {
return scope.$watch(function() {
var modelValue = ctrl.$modelValue;
if(isKeyTypedBadInput()) {
return { badInput: true };
}
return ctrl.$modelValue;
else if(!!_validationArrayObjprop && Array.isArray(modelValue) && modelValue.length === 0 && Object.keys(modelValue).length > 0) {
// when the modelValue is an Array but is length 0, this mean it's an Object disguise as an array
// since an Array of length 0 won't trigger a watch change, we need to return it back to an object
// for example Dropdown Multiselect when using selectionLimit of 1 will return [id: 1, label: 'John'], what we really want is the object { id: 1, label: 'John'}
// convert the object array to a real object that will go inside an array
var arr = [], obj = {};
obj[_validationArrayObjprop] = modelValue[_validationArrayObjprop]; // convert [label: 'John'] to {label: 'John'}
arr.push(obj); // push to array: [{label: 'John'}]
return arr;
}
return modelValue;
}, function(newValue, oldValue) {
if(!!newValue && !!newValue.badInput) {
unbindBlurHandler();
Expand Down
8 changes: 8 additions & 0 deletions src/validation-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,14 @@ angular
type: "regex"
};
break;
case "phoneInternational" :
case "phone_international" :
validator = {
pattern: /^\+(?:[0-9]\x20?){6,14}[0-9]$/,
message: "INVALID_PHONE_INTERNATIONAL",
type: "regex"
};
break;
case "pattern" :
case "regex" :
// Custom User Regex is a special case, the properties (message, pattern) were created and dealt separately prior to the for loop
Expand Down

0 comments on commit 5696c3a

Please sign in to comment.