aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2010-04-02 11:49:48 -0700
committerMisko Hevery2010-04-02 11:49:48 -0700
commit35ca4fcb9c49e505e28669e951e01ddedb01d7db (patch)
treee993e6fa5cb5ee24f8bb729d922425844c799e3a
parent5bd23fde7ab94646190d18d2891532feafad6e2e (diff)
downloadangular.js-35ca4fcb9c49e505e28669e951e01ddedb01d7db.tar.bz2
radio now works with repeaters
-rw-r--r--scenario/widgets.html2
-rw-r--r--src/Scope.js2
-rw-r--r--src/Widgets.js7
-rw-r--r--test/widgetsSpec.js1
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 @@
<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>
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(){
'</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();