From 67c59ec3ee5910c2ae6d69d828d11efb46813956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Tue, 27 Oct 2015 14:35:27 -0400 Subject: [PATCH 1/3] Checkboxradio: Properly find radio groups from the associated form Fixes #9973 --- ui/widgets/checkboxradio.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ui/widgets/checkboxradio.js b/ui/widgets/checkboxradio.js index b4f4de49dcb..bd2cada3ad6 100644 --- a/ui/widgets/checkboxradio.js +++ b/ui/widgets/checkboxradio.js @@ -93,9 +93,6 @@ $.widget( "ui.checkboxradio", [ $.ui.formResetMixin, { this._bindFormResetHandler(); - // this.form is set by the form-reset-mixin - this.formParent = this.form.length ? this.form : $( "body" ); - if ( this.options.disabled == null ) { this.options.disabled = this.element[ 0 ].disabled; } @@ -151,17 +148,25 @@ $.widget( "ui.checkboxradio", [ $.ui.formResetMixin, { }, _getRadioGroup: function() { + var group; var name = this.element[ 0 ].name; - var formParent = this.formParent[ 0 ]; + var nameSelector = "[name='" + $.ui.escapeSelector( name ) + "']"; if ( !name ) { return $( [] ); } - return this.formParent.find( "[name='" + $.ui.escapeSelector( name ) + "']" ).filter( function() { - var form = $( this ).form(); - return ( form.length ? form : $( "body" ) )[ 0 ] === formParent; - } ).not( this.element ); + if ( this.form.length ) { + group = $( this.form[ 0 ].elements ).filter( nameSelector ); + } else { + + // Not inside a form, check all inputs that also are not inside a form + group = $( nameSelector ).filter( function() { + return $( this ).form().length === 0; + } ); + } + + return group.not( this.element ); }, _toggleClasses: function() { From 5fcb55ab23b3f6972be79231899b40efb70698c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 28 Oct 2015 11:21:52 -0400 Subject: [PATCH 2/3] fixup: Add input to selector --- ui/widgets/checkboxradio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/widgets/checkboxradio.js b/ui/widgets/checkboxradio.js index bd2cada3ad6..10774920198 100644 --- a/ui/widgets/checkboxradio.js +++ b/ui/widgets/checkboxradio.js @@ -150,7 +150,7 @@ $.widget( "ui.checkboxradio", [ $.ui.formResetMixin, { _getRadioGroup: function() { var group; var name = this.element[ 0 ].name; - var nameSelector = "[name='" + $.ui.escapeSelector( name ) + "']"; + var nameSelector = "input[name='" + $.ui.escapeSelector( name ) + "']"; if ( !name ) { return $( [] ); From c58b94f0ef9d6d9c64dc3a3b83a53444d92864a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 28 Oct 2015 16:07:45 -0400 Subject: [PATCH 3/3] fixup: Add test --- tests/unit/checkboxradio/checkboxradio.html | 7 +++++++ tests/unit/checkboxradio/core.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/unit/checkboxradio/checkboxradio.html b/tests/unit/checkboxradio/checkboxradio.html index 92db788c5e8..9883e083403 100644 --- a/tests/unit/checkboxradio/checkboxradio.html +++ b/tests/unit/checkboxradio/checkboxradio.html @@ -64,6 +64,13 @@ + +
+ + + + + diff --git a/tests/unit/checkboxradio/core.js b/tests/unit/checkboxradio/core.js index 5fb13f58600..e5e8a809237 100644 --- a/tests/unit/checkboxradio/core.js +++ b/tests/unit/checkboxradio/core.js @@ -48,6 +48,25 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio } ); } ); +test( "Handle form association via form attribute", function( assert ) { + expect( 4 ); + + var radio1 = $( "#crazy-form-1" ).checkboxradio(); + var radio1Label = radio1.checkboxradio( "widget" ); + var radio2 = $( "#crazy-form-2" ).checkboxradio(); + var radio2Label = radio2.checkboxradio( "widget" ); + + radio2.change( function() { + ok( this.checked, "#2 checked" ); + ok( !radio1[ 0 ].checked, "#1 not checked" ); + + assert.hasClasses( radio2Label, "ui-state-active" ); + assert.lacksClasses( radio1Label, "ui-state-active" ); + } ); + + radio2Label.simulate( "click" ); +} ); + test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) { expect( 7 ); var groups = [