Compare commits

...

4 Commits

Author SHA1 Message Date
Pete Bacon Darwin dd26545870 docs(CHANGELOG): add 1.7.8 release notes 2019-03-11 11:30:02 +00:00
Martin Staffa a4c7bdccd7 fix(required): correctly validate required on non-input element surrounded by ngIf
Closes #16830
Closes #16836
2019-03-06 18:09:35 +01:00
Ashish Kamble edb3e22c01 docs(guide/di): clarify example description
Closes #16833
2019-03-05 22:01:01 +02:00
Pete Bacon Darwin 7446836e56 chore(scripts): use https for git repo URLs 2019-02-04 13:31:07 +00:00
6 changed files with 47 additions and 7 deletions
+11
View File
@@ -1,3 +1,14 @@
<a name="1.7.8"></a>
# 1.7.8 enthusiastic-oblation (2019-03-11)
## Bug Fixes
- **required:** correctly validate required on non-input element surrounded by ngIf
([a4c7bd](https://github.com/angular/angular.js/commit/a4c7bdccd76c39c30e33f6215da9a00cc8acde2c),
[#16830](https://github.com/angular/angular.js/issues/16830),
[#16836](https://github.com/angular/angular.js/issues/16836))
<a name="1.7.7"></a>
# 1.7.7 kingly-exiting (2019-02-04)
+8 -3
View File
@@ -279,15 +279,20 @@ construction and lookup of dependencies.
Here is an example of using the injector service:
First create an AngularJS module that will hold the service definition. (The empty array passed as
the second parameter means that this module does not depend on any other modules.)
```js
// Provide the wiring information in a module
// Create a module to hold the service definition
var myModule = angular.module('myModule', []);
```
Teach the injector how to build a `greeter` service. Notice that `greeter` is dependent on the
`$window` service. The `greeter` service is an object that contains a `greet` method.
Teach the injector how to build a `greeter` service, which is just an object that contains a `greet`
method. Notice that `greeter` is dependent on the `$window` service, which will be provided
(injected into `greeter`) by the injector.
```js
// Define the `greeter` service
myModule.factory('greeter', function($window) {
return {
greet: function(text) {
+1 -1
View File
@@ -27,7 +27,7 @@ function prepare {
for repo in "${REPOS[@]}"
do
echo "-- Cloning bower-$repo"
git clone git@github.com:angular/bower-$repo.git $TMP_DIR/bower-$repo --depth=1
git clone https://github.com/angular/bower-$repo.git $TMP_DIR/bower-$repo --depth=1
done
+1 -1
View File
@@ -25,7 +25,7 @@ function init {
function prepare {
echo "-- Cloning code.angularjs.org"
git clone git@github.com:angular/code.angularjs.org.git $REPO_DIR --depth=1
git clone https://github.com/angular/code.angularjs.org $REPO_DIR --depth=1
echo "-- Updating code.angularjs.org"
+8 -2
View File
@@ -68,15 +68,21 @@ var requiredDirective = ['$parse', function($parse) {
require: '?ngModel',
link: function(scope, elm, attr, ctrl) {
if (!ctrl) return;
var value = attr.required || $parse(attr.ngRequired)(scope);
// For boolean attributes like required, presence means true
var value = attr.hasOwnProperty('required') || $parse(attr.ngRequired)(scope);
attr.required = true; // force truthy in case we are on non input element
if (!attr.ngRequired) {
// force truthy in case we are on non input element
// (input elements do this automatically for boolean attributes like required)
attr.required = true;
}
ctrl.$validators.required = function(modelValue, viewValue) {
return !value || !ctrl.$isEmpty(viewValue);
};
attr.$observe('required', function(newVal) {
if (value !== newVal) {
value = newVal;
ctrl.$validate();
+18
View File
@@ -696,6 +696,13 @@ describe('validators', function() {
}));
it('should override "required" when ng-required="false" is set', function() {
var inputElm = helper.compileInput('<input type="text" ng-model="notDefined" required ng-required="false" />');
expect(inputElm).toBeValid();
});
it('should validate only once after compilation when inside ngRepeat', function() {
helper.compileInput(
'<div ng-repeat="input in [0]">' +
@@ -731,6 +738,7 @@ describe('validators', function() {
expect(helper.validationCounter.required).toBe(1);
});
it('should validate once when inside ngRepeat, and set the "required" error when ngRequired is false by default', function() {
$rootScope.isRequired = false;
$rootScope.refs = {};
@@ -744,5 +752,15 @@ describe('validators', function() {
expect($rootScope.refs.input.$error.required).toBeUndefined();
});
it('should validate only once when inside ngIf with required on non-input elements', inject(function($compile) {
$rootScope.value = '12';
$rootScope.refs = {};
helper.compileInput('<div ng-if="true"><span ng-model="value" ng-ref="refs.ctrl" ng-ref-read="ngModel" required validation-spy="required"></span></div>');
$rootScope.$digest();
expect(helper.validationCounter.required).toBe(1);
expect($rootScope.refs.ctrl.$error.required).not.toBe(true);
}));
});
});