radio now works with repeaters

This commit is contained in:
Misko Hevery 2010-04-02 11:49:48 -07:00
parent 5bd23fde7a
commit 35ca4fcb9c
4 changed files with 8 additions and 4 deletions

View file

@ -5,7 +5,7 @@
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
</head>
<body ng-init="$window.$scope = $root">
<table>
<table ng-repeat="i in [0, 1]">
<tr>
<th>Description</th>
<th>Test</th>

View file

@ -84,6 +84,7 @@ function errorHandlerFor(element, error) {
elementError(element, NG_EXCEPTION, isDefined(error) ? toJson(error) : error);
}
var scopeId = 0;
function createScope(parent, Class) {
function Parent(){}
function API(){}
@ -103,6 +104,7 @@ function createScope(parent, Class) {
extend(api, {
'this': instance,
$id: (scopeId++),
$parent: parent,
$bind: bind(instance, bind, instance),
$get: bind(instance, getter, instance),

View file

@ -111,8 +111,9 @@ function initWidgetValue(initValue) {
};
}
function radioInit(model, view) {
var modelValue = model.get(), viewValue = view.get();
function radioInit(model, view, element) {
var modelValue = model.get(), viewValue = view.get(), input = element[0];
input.name = this.$id + '@' + input.name;
if (isUndefined(modelValue)) model.set(null);
if (viewValue != null) model.set(viewValue);
}
@ -123,7 +124,7 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) {
model = modelAccessor(scope, element),
view = viewAccessor(scope, element),
action = element.attr('ng-change') || '';
initFn(model, view);
initFn.call(scope, model, view, element);
this.$eval(element.attr('ng-init')||'');
element.bind(events, function(){
model.set(view.get());

View file

@ -130,6 +130,7 @@ describe("input widget", function(){
'</div>');
var a = element[0].childNodes[0];
var b = element[0].childNodes[1];
expect(b.name.split('@')[1]).toEqual('chose');
expect(scope.chose).toEqual('B');
scope.chose = 'A';
scope.$eval();