r3585 committed - button: enhancement for radio buttons to take their form into consider...

r3585 committed - button: enhancement for radio buttons to take their form into consider...

Revision: 3585
Author: joern.zaefferer
Date: Sat Jan 2 03:54:14 2010
Log: button: enhancement for radio buttons to take their form into
consideration, making multiple sets of radio buttons with the same name
across different forms work; removed the auto-initialization of
other-radio-buttons in order to initialize only what we later can safely
destroy
http://code.google.com/p/jquery-ui/source/detail?r=3585
Modified:
/branches/dev/tests/visual/button/default.html
/branches/dev/ui/jquery.ui.button.js
=======================================
--- /branches/dev/tests/visual/button/default.html    Wed Dec 30 19:18:21 2009
+++ /branches/dev/tests/visual/button/default.html    Sat Jan 2 03:54:14 2010
@@ -18,7 +18,7 @@
    <script type="text/javascript">
    $(function() {
        var buttons = $('#push button, #check').button();
-        var buttonSets = $('#radio, #ops1, #format, #ops2, #mode, #inputs,
#anchors').buttonset();
+        var buttonSets = $('#radio1, #radio2, #ops1, #format, #ops2, #mode,
#inputs, #anchors').buttonset();
        buttons.add(buttonSets).click(function(event) {
            $("<div></div>").text("Clicked " + $(event.target).text() + " (#" +
event.target.id + ")").appendTo("#log");
@@ -63,11 +63,20 @@
    <input type="checkbox" id="check" /><label for="check">Toggle</label>
</div>
-<div id="radio" style="margin-top: 2em;">
-    <input type="radio" id="radio1" name="radio1" /><label
for="radio1">Choice 1</label>
-    <input type="radio" id="radio2" name="radio1" /><label
for="radio2">Choice 2</label>
-    <input type="radio" id="radio3" name="radio1" /><label
for="radio3">Choice 3</label>
-</div>
+<form>
+    <div id="radio1" style="margin-top: 2em;">
+        <input type="radio" id="radio11" name="radio" /><label
for="radio11">Choice 1</label>
+        <input type="radio" id="radio12" name="radio" /><label
for="radio12">Choice 2</label>
+        <input type="radio" id="radio13" name="radio" /><label
for="radio13">Choice 3</label>
+    </div>
+</form>
+<form>
+    <div id="radio2" style="margin-top: 2em;">
+        <input type="radio" id="radio21" name="radio" /><label
for="radio21">Choice 1</label>
+        <input type="radio" id="radio22" name="radio" /><label
for="radio22">Choice 2</label>
+        <input type="radio" id="radio23" name="radio" /><label
for="radio23">Choice 3</label>
+    </div>
+</form>
<div id="toolbar" class="ui-widget-header ui-corner-all
ui-helper-clearfix">
    <span id="ops1">
=======================================
--- /branches/dev/ui/jquery.ui.button.js    Wed Dec 30 19:05:02 2009
+++ /branches/dev/ui/jquery.ui.button.js    Sat Jan 2 03:54:14 2010
@@ -70,7 +70,8 @@
                    self.element
                        .attr("checked", true)
                        .click();
-                    $('[name=' + self.element.attr('name') + ']')
+                    // restrict search for the other buttons to the form, if present
+                    $('[name=' + self.element.attr('name') + ']', self.element[0].form ||
document)
                        .not(self.element)
                        .map(function() {
                            return $(this).button('widget')[0];
@@ -107,10 +108,6 @@
                    ? 'input'
                    : 'button';
-        if (this.type == 'radio') {
-            $('[name=' + this.element.attr('name') + ']').button();
-        }
-
        if (this.type == 'checkbox' || this.type == 'radio') {
            this.buttonElement = $("[for=" + this.element.attr("id") + "]");
            this.element.hide();
--