From 35ca4fcb9c49e505e28669e951e01ddedb01d7db Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 2 Apr 2010 11:49:48 -0700 Subject: radio now works with repeaters --- scenario/widgets.html | 2 +- src/Scope.js | 2 ++ src/Widgets.js | 7 ++++--- test/widgetsSpec.js | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scenario/widgets.html b/scenario/widgets.html index c2042b68..64e48c54 100644 --- a/scenario/widgets.html +++ b/scenario/widgets.html @@ -5,7 +5,7 @@
-| Description | Test | diff --git a/src/Scope.js b/src/Scope.js index 2b2db189..26a3f85b 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -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), diff --git a/src/Widgets.js b/src/Widgets.js index e42d981c..a05ea63c 100644 --- a/src/Widgets.js +++ b/src/Widgets.js @@ -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()); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 6c47e5dd..a4afa21c 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -130,6 +130,7 @@ describe("input widget", function(){ ''); 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(); -- cgit v1.2.3
|---|