Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

test
  • Loading branch information...
commit cf21c53520a60a689d57c3187daba1cf25f160b5 1 parent 3120f53
@jokeyrhyme jokeyrhyme authored Wilto committed
View
9 js/jquery.mobile.forms.checkboxradio.js
@@ -42,6 +42,15 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
return;
}
+ // check for <label><input /></label> structure
+ if (!label.length) {
+ label = $(input).closest('label');
+ // <label> is only implicitly for its first label-able descendant
+ if (!label.find('button, input[type!="hidden"], keygen, meter, output, progress, select, textarea').first().is(input)) {
+ label = $('');
+ }
+ }
+
if( !label.length ){
this.raise( inputtype + " inputs require a label for enhancement" );
}
View
38 tests/unit/checkboxradio/checkboxradio_core.js
@@ -129,7 +129,7 @@
ok( !$("input.should-be-native").parent().is("div.ui-checkbox") );
});
- test( "Elements with “data-mini='true' should have “ui-mini” class attached to enhanced element.", function(){
+ test( "Elements with “data-mini='true'� should have “ui-mini� class attached to enhanced element.", function(){
var full = document.getElementById("radio-full"),
$fulllbl = $('[for="radio-full"]'),
mini = document.getElementById("radio-mini"),
@@ -249,18 +249,30 @@
}
});
- test( "nested label checkbox still renders", function() {
- var $checkbox = $( "#checkbox-nested-label" );
-
- try {
- $checkbox.checkboxradio();
- } catch (e) {
- ok( false, "checkboxradio exception raised: " + e.toString());
- }
-
- ok( $checkbox.parent().hasClass("ui-checkbox"), "enhancement has occured");
- });
-
+ test( "nested label checkbox still renders", function() {
+ var $checkbox = $( "#checkbox-nested-label" );
+
+ try {
+ $checkbox.checkboxradio();
+ } catch (e) {
+ ok( false, "checkboxradio exception raised: " + e.toString());
+ }
+
+ ok( $checkbox.parent().hasClass("ui-checkbox"), "enhancement has occured");
+ });
+
+ test( "nested label (no [for]) checkbox still renders", function() {
+ var $checkbox = $( "#checkbox-nested-label-no-for" );
+
+ try {
+ $checkbox.checkboxradio();
+ } catch (e) {
+ ok( false, "checkboxradio exception raised: " + e.toString());
+ }
+
+ ok( $checkbox.parent().hasClass("ui-checkbox"), "enhancement has occured");
+ });
+
test( "Icon positioning", function() {
var bottomicon = $("[for='bottomicon']")
topicon = $("[for='topicon']");
View
8 tests/unit/checkboxradio/index.html
@@ -190,5 +190,13 @@ <h2 id="qunit-userAgent"></h2>
</label>
</form>
</div>
+
+<div id="nested-label-no-for-test">
+ <form>
+ <label>
+ <input type="checkbox" name="checkbox-nested-label-no-for" id="checkbox-nested-label-no-for" class="custom"/>
+ </label>
+ </form>
+</div>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.