Skip to content
This repository
Browse code

fix checkboxradio to cope with <label><input /></label> and add new unit

test
  • Loading branch information...
commit cf21c53520a60a689d57c3187daba1cf25f160b5 1 parent 3120f53
Ron Waldon authored March 24, 2012 Wilto committed March 26, 2012
9  js/jquery.mobile.forms.checkboxradio.js
@@ -42,6 +42,15 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
42 42
 			return;
43 43
 		}
44 44
 
  45
+		// check for <label><input /></label> structure
  46
+		if (!label.length) {
  47
+		  label = $(input).closest('label');
  48
+		  // <label> is only implicitly for its first label-able descendant
  49
+		  if (!label.find('button, input[type!="hidden"], keygen, meter, output, progress, select, textarea').first().is(input)) {
  50
+		    label = $('');
  51
+		  }
  52
+		}
  53
+		
45 54
 		if( !label.length ){
46 55
 			this.raise( inputtype + " inputs require a label for enhancement" );
47 56
 		}
38  tests/unit/checkboxradio/checkboxradio_core.js
@@ -129,7 +129,7 @@
129 129
 		ok( !$("input.should-be-native").parent().is("div.ui-checkbox") );
130 130
 	});
131 131
 
132  
-	test( "Elements with “data-mini='true'” should have “ui-mini” class attached to enhanced element.", function(){
  132
+	test( "Elements with “data-mini='true'� should have “ui-mini� class attached to enhanced element.", function(){
133 133
 		var full = document.getElementById("radio-full"),
134 134
 			$fulllbl = $('[for="radio-full"]'),
135 135
 			mini = document.getElementById("radio-mini"),
@@ -249,18 +249,30 @@
249 249
 		}
250 250
 	});
251 251
 
252  
-	test( "nested label checkbox still renders", function() {
253  
-		var $checkbox = $( "#checkbox-nested-label" );
254  
-
255  
-		try {
256  
-			$checkbox.checkboxradio();
257  
-		} catch (e) {
258  
-			ok( false, "checkboxradio exception raised: " + e.toString());
259  
-		}
260  
-
261  
-		ok( $checkbox.parent().hasClass("ui-checkbox"), "enhancement has occured");
262  
-	});
263  
-	
  252
+  test( "nested label checkbox still renders", function() {
  253
+    var $checkbox = $( "#checkbox-nested-label" );
  254
+
  255
+    try {
  256
+      $checkbox.checkboxradio();
  257
+    } catch (e) {
  258
+      ok( false, "checkboxradio exception raised: " + e.toString());
  259
+    }
  260
+
  261
+    ok( $checkbox.parent().hasClass("ui-checkbox"), "enhancement has occured");
  262
+  });
  263
+  
  264
+  test( "nested label (no [for]) checkbox still renders", function() {
  265
+    var $checkbox = $( "#checkbox-nested-label-no-for" );
  266
+
  267
+    try {
  268
+      $checkbox.checkboxradio();
  269
+    } catch (e) {
  270
+      ok( false, "checkboxradio exception raised: " + e.toString());
  271
+    }
  272
+
  273
+    ok( $checkbox.parent().hasClass("ui-checkbox"), "enhancement has occured");
  274
+  });
  275
+  
264 276
 	test( "Icon positioning", function() {
265 277
 		var bottomicon = $("[for='bottomicon']")
266 278
 			topicon = $("[for='topicon']");
8  tests/unit/checkboxradio/index.html
@@ -190,5 +190,13 @@ <h2 id="qunit-userAgent"></h2>
190 190
 		</label>
191 191
 	</form>
192 192
 </div>
  193
+
  194
+<div id="nested-label-no-for-test">
  195
+  <form>
  196
+    <label>
  197
+      <input type="checkbox" name="checkbox-nested-label-no-for" id="checkbox-nested-label-no-for" class="custom"/>
  198
+    </label>
  199
+  </form>
  200
+</div>
193 201
 </body>
194 202
 </html>

0 notes on commit cf21c53

Please sign in to comment.
Something went wrong with that request. Please try again.