mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Closes #153: input widgets without name are ignored
This commit is contained in:
parent
b225083a21
commit
ec4d446f89
3 changed files with 51 additions and 37 deletions
|
|
@ -1,5 +1,7 @@
|
|||
# <angular/> 0.9.8 astral-projection (in-progress) #
|
||||
|
||||
### Bug Fixes
|
||||
- Ignore input widgets which have no name (issue #153)
|
||||
|
||||
# <angular/> 0.9.7 sonic-scream (2010-12-10) #
|
||||
|
||||
|
|
|
|||
|
|
@ -134,17 +134,18 @@
|
|||
|
||||
function modelAccessor(scope, element) {
|
||||
var expr = element.attr('name');
|
||||
if (!expr) throw "Required field 'name' not found.";
|
||||
return {
|
||||
get: function() {
|
||||
return scope.$eval(expr);
|
||||
},
|
||||
set: function(value) {
|
||||
if (value !== _undefined) {
|
||||
return scope.$tryEval(expr + '=' + toJson(value), element);
|
||||
if (expr) {
|
||||
return {
|
||||
get: function() {
|
||||
return scope.$eval(expr);
|
||||
},
|
||||
set: function(value) {
|
||||
if (value !== _undefined) {
|
||||
return scope.$tryEval(expr + '=' + toJson(value), element);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function modelFormattedAccessor(scope, element) {
|
||||
|
|
@ -152,14 +153,16 @@ function modelFormattedAccessor(scope, element) {
|
|||
formatterName = element.attr('ng:format') || NOOP,
|
||||
formatter = angularFormatter(formatterName);
|
||||
if (!formatter) throw "Formatter named '" + formatterName + "' not found.";
|
||||
return {
|
||||
get: function() {
|
||||
return formatter.format(accessor.get());
|
||||
},
|
||||
set: function(value) {
|
||||
return accessor.set(formatter.parse(value));
|
||||
}
|
||||
};
|
||||
if (accessor) {
|
||||
return {
|
||||
get: function() {
|
||||
return formatter.format(accessor.get());
|
||||
},
|
||||
set: function(value) {
|
||||
return accessor.set(formatter.parse(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function compileValidator(expr) {
|
||||
|
|
@ -458,25 +461,27 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn, dirtyChecking)
|
|||
view = viewAccessor(scope, element),
|
||||
action = element.attr('ng:change') || '',
|
||||
lastValue;
|
||||
initFn.call(scope, model, view, element);
|
||||
this.$eval(element.attr('ng:init')||'');
|
||||
// Don't register a handler if we are a button (noopAccessor) and there is no action
|
||||
if (action || modelAccessor !== noopAccessor) {
|
||||
element.bind(events, function (){
|
||||
var value = view.get();
|
||||
if (!dirtyChecking || value != lastValue) {
|
||||
model.set(value);
|
||||
lastValue = model.get();
|
||||
scope.$tryEval(action, element);
|
||||
scope.$root.$eval();
|
||||
if (model) {
|
||||
initFn.call(scope, model, view, element);
|
||||
this.$eval(element.attr('ng:init')||'');
|
||||
// Don't register a handler if we are a button (noopAccessor) and there is no action
|
||||
if (action || modelAccessor !== noopAccessor) {
|
||||
element.bind(events, function (){
|
||||
var value = view.get();
|
||||
if (!dirtyChecking || value != lastValue) {
|
||||
model.set(value);
|
||||
lastValue = model.get();
|
||||
scope.$tryEval(action, element);
|
||||
scope.$root.$eval();
|
||||
}
|
||||
});
|
||||
}
|
||||
scope.$watch(model.get, function(value){
|
||||
if (lastValue !== value) {
|
||||
view.set(lastValue = value);
|
||||
}
|
||||
});
|
||||
}
|
||||
scope.$watch(model.get, function(value){
|
||||
if (lastValue !== value) {
|
||||
view.set(lastValue = value);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -452,10 +452,17 @@ describe("widget", function(){
|
|||
scope.$eval();
|
||||
expect(element[0].childNodes[0].selected).toEqual(true);
|
||||
});
|
||||
|
||||
it('should report error on missing field', function(){
|
||||
|
||||
it('should ignore text widget which have no name', function(){
|
||||
compile('<input type="text"/>');
|
||||
expect(element.hasClass('ng-exception')).toBeTruthy();
|
||||
expect(scope.$element.attr('ng-exception')).toBeFalsy();
|
||||
expect(scope.$element.hasClass('ng-exception')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should ignore checkbox widget which have no name', function(){
|
||||
compile('<input type="checkbox"/>');
|
||||
expect(scope.$element.attr('ng-exception')).toBeFalsy();
|
||||
expect(scope.$element.hasClass('ng-exception')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should report error on assignment error', function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue