Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cd03fe9

Browse files
author
Misko Hevery
committed
checkbox widget fix
1 parent e8ac57c commit cd03fe9

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

angular-debug.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,13 +3185,13 @@ function valueAccessor(scope, element) {
31853185
}
31863186

31873187
function checkedAccessor(scope, element) {
3188-
var domElement = element[0];
3188+
var domElement = element[0], elementValue = domElement.value;
31893189
return {
31903190
get: function(){
31913191
return !!domElement.checked;
31923192
},
31933193
set: function(value){
3194-
domElement.checked = !!value;
3194+
domElement.checked = toBoolean(value);
31953195
}
31963196
};
31973197
}
@@ -3444,8 +3444,13 @@ angularService("$location", function(browser){
34443444
scope.$root.$eval();
34453445
});
34463446
parse(browser.getUrl());
3447+
var lastURL;
34473448
this.$onEval(PRIORITY_LAST, function(){
3448-
browser.setUrl(toString());
3449+
var url = toString();
3450+
if (lastURL != url) {
3451+
browser.setUrl(url);
3452+
lastURL = url;
3453+
}
34493454
});
34503455
return location;
34513456
}, {inject: ['$browser']});

src/services.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ angularService("$location", function(browser){
4444
scope.$root.$eval();
4545
});
4646
parse(browser.getUrl());
47+
var lastURL;
4748
this.$onEval(PRIORITY_LAST, function(){
48-
browser.setUrl(toString());
49+
var url = toString();
50+
if (lastURL != url) {
51+
browser.setUrl(url);
52+
lastURL = url;
53+
}
4954
});
5055
return location;
5156
}, {inject: ['$browser']});

src/widgets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ function valueAccessor(scope, element) {
4949
}
5050

5151
function checkedAccessor(scope, element) {
52-
var domElement = element[0];
52+
var domElement = element[0], elementValue = domElement.value;
5353
return {
5454
get: function(){
5555
return !!domElement.checked;
5656
},
5757
set: function(value){
58-
domElement.checked = !!value;
58+
domElement.checked = toBoolean(value);
5959
}
6060
};
6161
}

test/widgetsSpec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ describe("input widget", function(){
66
scope = null;
77
element = null;
88
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
9-
compile = function(html) {
9+
compile = function(html, before) {
1010
element = jqLite(html);
1111
scope = compiler.compile(element)(element);
12+
(before||noop)();
1213
scope.$init();
1314
};
1415
});
@@ -51,6 +52,14 @@ describe("input widget", function(){
5152
expect(scope.$get('list')).toEqual(['1', '2', '3']);
5253
});
5354

55+
it("should process ng-format for booleans", function(){
56+
compile('<input type="checkbox" name="name" value="true" ng-format="boolean"/>', function(){
57+
scope.name = false;
58+
});
59+
expect(scope.name).toEqual(false);
60+
expect(scope.$element[0].checked).toEqual(false);
61+
});
62+
5463
it("should process ng-validation", function(){
5564
compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
5665
expect(element.hasClass('ng-validation-error')).toBeTruthy();

0 commit comments

Comments
 (0)