mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-05 21:54:42 +00:00
checkbox widget fix
This commit is contained in:
parent
e8ac57caae
commit
cd03fe92a5
4 changed files with 26 additions and 7 deletions
11
angular-debug.js
vendored
11
angular-debug.js
vendored
|
|
@ -3185,13 +3185,13 @@ function valueAccessor(scope, element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkedAccessor(scope, element) {
|
function checkedAccessor(scope, element) {
|
||||||
var domElement = element[0];
|
var domElement = element[0], elementValue = domElement.value;
|
||||||
return {
|
return {
|
||||||
get: function(){
|
get: function(){
|
||||||
return !!domElement.checked;
|
return !!domElement.checked;
|
||||||
},
|
},
|
||||||
set: function(value){
|
set: function(value){
|
||||||
domElement.checked = !!value;
|
domElement.checked = toBoolean(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -3444,8 +3444,13 @@ angularService("$location", function(browser){
|
||||||
scope.$root.$eval();
|
scope.$root.$eval();
|
||||||
});
|
});
|
||||||
parse(browser.getUrl());
|
parse(browser.getUrl());
|
||||||
|
var lastURL;
|
||||||
this.$onEval(PRIORITY_LAST, function(){
|
this.$onEval(PRIORITY_LAST, function(){
|
||||||
browser.setUrl(toString());
|
var url = toString();
|
||||||
|
if (lastURL != url) {
|
||||||
|
browser.setUrl(url);
|
||||||
|
lastURL = url;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return location;
|
return location;
|
||||||
}, {inject: ['$browser']});
|
}, {inject: ['$browser']});
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,13 @@ angularService("$location", function(browser){
|
||||||
scope.$root.$eval();
|
scope.$root.$eval();
|
||||||
});
|
});
|
||||||
parse(browser.getUrl());
|
parse(browser.getUrl());
|
||||||
|
var lastURL;
|
||||||
this.$onEval(PRIORITY_LAST, function(){
|
this.$onEval(PRIORITY_LAST, function(){
|
||||||
browser.setUrl(toString());
|
var url = toString();
|
||||||
|
if (lastURL != url) {
|
||||||
|
browser.setUrl(url);
|
||||||
|
lastURL = url;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return location;
|
return location;
|
||||||
}, {inject: ['$browser']});
|
}, {inject: ['$browser']});
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,13 @@ function valueAccessor(scope, element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkedAccessor(scope, element) {
|
function checkedAccessor(scope, element) {
|
||||||
var domElement = element[0];
|
var domElement = element[0], elementValue = domElement.value;
|
||||||
return {
|
return {
|
||||||
get: function(){
|
get: function(){
|
||||||
return !!domElement.checked;
|
return !!domElement.checked;
|
||||||
},
|
},
|
||||||
set: function(value){
|
set: function(value){
|
||||||
domElement.checked = !!value;
|
domElement.checked = toBoolean(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@ describe("input widget", function(){
|
||||||
scope = null;
|
scope = null;
|
||||||
element = null;
|
element = null;
|
||||||
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
|
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
|
||||||
compile = function(html) {
|
compile = function(html, before) {
|
||||||
element = jqLite(html);
|
element = jqLite(html);
|
||||||
scope = compiler.compile(element)(element);
|
scope = compiler.compile(element)(element);
|
||||||
|
(before||noop)();
|
||||||
scope.$init();
|
scope.$init();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
@ -51,6 +52,14 @@ describe("input widget", function(){
|
||||||
expect(scope.$get('list')).toEqual(['1', '2', '3']);
|
expect(scope.$get('list')).toEqual(['1', '2', '3']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should process ng-format for booleans", function(){
|
||||||
|
compile('<input type="checkbox" name="name" value="true" ng-format="boolean"/>', function(){
|
||||||
|
scope.name = false;
|
||||||
|
});
|
||||||
|
expect(scope.name).toEqual(false);
|
||||||
|
expect(scope.$element[0].checked).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("should process ng-validation", function(){
|
it("should process ng-validation", function(){
|
||||||
compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
|
compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
|
||||||
expect(element.hasClass('ng-validation-error')).toBeTruthy();
|
expect(element.hasClass('ng-validation-error')).toBeTruthy();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue