Skip to content

Commit

Permalink
provider validate reset doesn't need parameter scope anymore
Browse files Browse the repository at this point in the history
provider $rootScope fix it
  • Loading branch information
hueitan committed Feb 9, 2014
1 parent 34b8023 commit 51f0019
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Add Valid Callback Function, `invalid-callback` & `valid-callback`
```

Select the validation method `watch` `blur` `submit`, default as `watch`<br/>
`validationProvider.validate($scope, form).success(callback).error(callback)` use callback to continue your submit
`validationProvider.validate(form).success(callback).error(callback)` use callback to continue your submit

```html
<label>Watch method</label>
Expand All @@ -94,7 +94,7 @@ Select the validation method `watch` `blur` `submit`, default as `watch`<br/>
// ... validate method, it will check `checkValid(Form)`
$scope.form = {
submit: function () {
$validationProvider.validate($scope, form)
$validationProvider.validate(form)
.success(successCallback)
.error(errorCallback);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ Reset the specific Form. `reset()`
$scope.form.checkValid = validationProvider.checkValid;
// ... reset
$scope.form.reset = function (form) {
validationProvider.reset($scope, form);
validationProvider.reset(form);
};
```

Expand Down
12 changes: 6 additions & 6 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ angular.module('myApp', ['validation'])
requiredCallback: 'required',
checkValid: $validationProvider.checkValid,
submit: function (form) {
$validationProvider.validate($scope, form);
$validationProvider.validate(form);
},
reset: function (form) {
$validationProvider.reset($scope, form);
$validationProvider.reset(form);
}
};

$scope.form2 = {
checkValid: $validationProvider.checkValid,
submit: function (form) {
$validationProvider.validate($scope, form);
$validationProvider.validate(form);
},
reset: function (form) {
$validationProvider.reset($scope, form);
$validationProvider.reset(form);
}
};

$scope.form3 = {
checkValid: $validationProvider.checkValid,
submit: function (form) {
$validationProvider.validate($scope, form)
$validationProvider.validate(form)
.success($scope.success)
.error($scope.error);
},
reset: function (form) {
$validationProvider.reset($scope, form);
$validationProvider.reset(form);
}
};

Expand Down
12 changes: 6 additions & 6 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


var $injector,
$scope,
$http,
$q,
_this = this;
Expand All @@ -18,6 +19,7 @@
*/
var setup = function (injector) {
$injector = injector;
$scope = $injector.get('$rootScope');
$http = $injector.get('$http');
$q = $injector.get('$q');
};
Expand Down Expand Up @@ -159,15 +161,14 @@

/**
* Validate the form when click submit, when `validMethod = submit`
* @param scope
* @param form
* @returns {promise|*}
*/
this.validate = function (scope, form) {
this.validate = function (form) {

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

Expand Down Expand Up @@ -199,17 +200,16 @@

/**
* reset the specific form
* @param scope
* @param form
*/
this.reset = function (scope, form) {
this.reset = function (form) {
for (var k in form) {
if (form[k].hasOwnProperty('$dirty')) {
form[k].$setViewValue(null);
form[k].$setPristine();
form[k].$setValidity(form[k].$name, false);
form[k].$render();
scope.$broadcast(k + 'reset');
$scope.$broadcast(k + 'reset');
}
}
};
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.

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


var $injector,
$scope,
$http,
$q,
_this = this;
Expand All @@ -15,6 +16,7 @@
*/
var setup = function (injector) {
$injector = injector;
$scope = $injector.get('$rootScope');
$http = $injector.get('$http');
$q = $injector.get('$q');
};
Expand Down Expand Up @@ -156,15 +158,14 @@

/**
* Validate the form when click submit, when `validMethod = submit`
* @param scope
* @param form
* @returns {promise|*}
*/
this.validate = function (scope, form) {
this.validate = function (form) {

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

Expand Down Expand Up @@ -196,17 +197,16 @@

/**
* reset the specific form
* @param scope
* @param form
*/
this.reset = function (scope, form) {
this.reset = function (form) {
for (var k in form) {
if (form[k].hasOwnProperty('$dirty')) {
form[k].$setViewValue(null);
form[k].$setPristine();
form[k].$setValidity(form[k].$name, false);
form[k].$render();
scope.$broadcast(k + 'reset');
$scope.$broadcast(k + 'reset');
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions test/unit/providerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('provider', function () {
$scope.$on('requiredreset', function () {
resetSpy();
});
validationProvider.reset($scope, $scope.Form);
validationProvider.reset($scope.Form);
expect(element.find('p')[0]).toBeUndefined();
expect(resetSpy).toHaveBeenCalled();
}));
Expand All @@ -130,7 +130,7 @@ describe('provider', function () {
$scope.$apply(function () {
$scope.required = 'Required';
});
validationProvider.validate($scope, $scope.Form)
validationProvider.validate($scope.Form)
.success(function () {
successSpy();
})
Expand All @@ -152,7 +152,7 @@ describe('provider', function () {
submitSpy2();
});

validationProvider.validate($scope, $scope.Form)
validationProvider.validate($scope.Form)
.success(function () {
successSpy2();
})
Expand Down

0 comments on commit 51f0019

Please sign in to comment.