Skip to content

Commit

Permalink
unique field event #22
Browse files Browse the repository at this point in the history
Thanks @gilad1987
  • Loading branch information
hueitan committed Jun 15, 2014
1 parent 23b5bbe commit af5ea19
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
24 changes: 20 additions & 4 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@

for (var k in form) {
if (form[k].hasOwnProperty('$dirty')) {
$scope.$broadcast(k + 'submit', idx++);
$scope.$broadcast(k + 'submit-' + form[k].validationId, idx++);
}
}

Expand Down Expand Up @@ -229,7 +229,7 @@
this.reset = function (form) {
for (var k in form) {
if (form[k].hasOwnProperty('$dirty')) {
$scope.$broadcast(k + 'reset');
$scope.$broadcast(k + 'reset-' + form[k].validationId);
}
}
};
Expand Down Expand Up @@ -366,6 +366,17 @@
};


/**
* generate unique guid
*/
var s4 = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
var guid = function () {
return (s4() + s4() + s4() + s4());
};


return {
restrict: 'A',
require: 'ngModel',
Expand Down Expand Up @@ -394,6 +405,11 @@
*/
var validator = attrs.validator.split(',');

/**
* guid use
*/
var uid = ctrl.validationId = guid();

/**
* Valid/Invalid Message
*/
Expand All @@ -407,7 +423,7 @@
/**
* Reset the validation for specific form
*/
scope.$on(ctrl.$name + 'reset', function () {
scope.$on(ctrl.$name + 'reset-' + uid, function () {

/**
* clear scope.$watch here
Expand All @@ -433,7 +449,7 @@
/**
* Click submit form, check the validity when submit
*/
scope.$on(ctrl.$name + 'submit', function (event, index) {
scope.$on(ctrl.$name + 'submit-' + uid, function (event, index) {
var value = element[0].value,
isValid = false;

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ <h1>Angular Validation.
<div class="row">
<div class="small-12 medium-12 large-6 columns">
<form name="Form" id="form1">
{{ Form }}
<fieldset>
<legend>Form ($watch)</legend>

Expand Down
20 changes: 18 additions & 2 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@
};


/**
* generate unique guid
*/
var s4 = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
var guid = function () {
return (s4() + s4() + s4() + s4());
};


return {
restrict: 'A',
require: 'ngModel',
Expand Down Expand Up @@ -131,6 +142,11 @@
*/
var validator = attrs.validator.split(',');

/**
* guid use
*/
var uid = ctrl.validationId = guid();

/**
* Valid/Invalid Message
*/
Expand All @@ -144,7 +160,7 @@
/**
* Reset the validation for specific form
*/
scope.$on(ctrl.$name + 'reset', function () {
scope.$on(ctrl.$name + 'reset-' + uid, function () {

/**
* clear scope.$watch here
Expand All @@ -170,7 +186,7 @@
/**
* Click submit form, check the validity when submit
*/
scope.$on(ctrl.$name + 'submit', function (event, index) {
scope.$on(ctrl.$name + 'submit-' + uid, function (event, index) {
var value = element[0].value,
isValid = false;

Expand Down
4 changes: 2 additions & 2 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@

for (var k in form) {
if (form[k].hasOwnProperty('$dirty')) {
$scope.$broadcast(k + 'submit', idx++);
$scope.$broadcast(k + 'submit-' + form[k].validationId, idx++);
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@
this.reset = function (form) {
for (var k in form) {
if (form[k].hasOwnProperty('$dirty')) {
$scope.$broadcast(k + 'reset');
$scope.$broadcast(k + 'reset-' + form[k].validationId);
}
}
};
Expand Down

0 comments on commit af5ea19

Please sign in to comment.