Skip to content

Commit cb7a5dc

Browse files
author
Gabriel Schulhof
committed
Checkboxradio: When pre-rendered, assume label is a sibling of the input
Closes jquery-archivegh-7471 Fixes jquery-archivegh-7470
1 parent 1ed6f92 commit cb7a5dc

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

js/widgets/forms/checkboxradio.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ $.widget( "mobile.checkboxradio", $.extend( {
3939
return input.jqmData( dataAttr ) ||
4040
input.closest( "form, fieldset" ).jqmData( dataAttr );
4141
},
42-
label = this._findLabel(),
42+
label = this.options.enhanced ?
43+
{
44+
element: this.element.siblings( "label" ),
45+
isParent: false
46+
} :
47+
this._findLabel(),
4348
inputtype = input[0].type,
4449
checkedClass = "ui-" + inputtype + "-on",
4550
uncheckedClass = "ui-" + inputtype + "-off";

tests/unit/checkboxradio/find-label-tests.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,12 @@
4040
<label id="separate-label-input-outside-form-label" for="separate-label-input-outside-form">Label</label>
4141
<input type="checkbox" id="separate-label-input-outside-form">
4242
<label id="nested-input-outside-form-label">Label<input type="checkbox" id="nested-input-outside-form"></label>
43+
44+
<form>
45+
<div class="ui-checkbox">
46+
<label class="ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-checkbox-off">Pre-rendered</label>
47+
<input type="checkbox" id="pre-rendered-label-test" data-nstest-enhanced="true">
48+
</div>
49+
</form>
4350
</body>
4451
</html>

tests/unit/checkboxradio/find_label_tests_core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
$.mobile.ns = "nstest-";
2+
13
var pairs = [
24
{
35
label: "#separate-label-outside-form-label",
@@ -49,3 +51,13 @@ test( "_findLabel() works correctly", function() {
4951
": the label was correctly identified as (not?) the parent" );
5052
}
5153
});
54+
55+
test( "label on pre-rendered checkbox is found", function() {
56+
var actualLabel = $( "#pre-rendered-label-test" )
57+
.checkboxradio()
58+
.data( "mobile-checkboxradio" ).label,
59+
expectedLabel = $( "#pre-rendered-label-test" ).prev();
60+
61+
deepEqual( actualLabel.length, 1, "One label was found" );
62+
deepEqual( actualLabel[ 0 ], expectedLabel[ 0 ], "The right label was found" );
63+
});

0 commit comments

Comments
 (0)