From 0b30a1d450f6b7d529732d6a39c5f4057efaaaf4 Mon Sep 17 00:00:00 2001 From: ddstreet Date: Fri, 11 Mar 2011 10:52:13 -0500 Subject: Button: find associated label even without common ancestor. Fixes #7092 - button creation that requires a matching label does not find label in all cases --- ui/jquery.ui.button.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index 134dae3d3..9cf8974b2 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -201,8 +201,16 @@ $.widget( "ui.button", { if ( this.type === "checkbox" || this.type === "radio" ) { // we don't search against the document in case the element // is disconnected from the DOM - this.buttonElement = this.element.parents().last() - .find( "label[for=" + this.element.attr("id") + "]" ); + var ancestor = this.element.parents().last(), + labelSelector = "label[for=" + this.element.attr("id") + "]"; + this.buttonElement = ancestor.find( labelSelector ); + if ( !this.buttonElement.length ) { + ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings(); + this.buttonElement = ancestor.filter( labelSelector ); + if ( !this.buttonElement.length ) { + this.buttonElement = ancestor.find( labelSelector ); + } + } this.element.addClass( "ui-helper-hidden-accessible" ); var checked = this.element.is( ":checked" ); -- cgit v1.2.3