Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Checkboxradio: When pre-rendered, assume label is a sibling of the input
Browse files Browse the repository at this point in the history
(cherry picked from commit cb7a5dc)

Closes gh-7471
Fixes gh-7470
  • Loading branch information
Gabriel Schulhof committed Jun 5, 2014
1 parent 05f409d commit 9aa1f30
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/widgets/forms/checkboxradio.js
Expand Up @@ -39,7 +39,12 @@ $.widget( "mobile.checkboxradio", $.extend( {
return input.jqmData( dataAttr ) ||
input.closest( "form, fieldset" ).jqmData( dataAttr );
},
label = this._findLabel(),
label = this.options.enhanced ?
{
element: this.element.siblings( "label" ),
isParent: false
} :
this._findLabel(),
inputtype = input[0].type,
checkedClass = "ui-" + inputtype + "-on",
uncheckedClass = "ui-" + inputtype + "-off";
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/checkboxradio/find-label-tests.html
Expand Up @@ -40,5 +40,12 @@
<label id="separate-label-input-outside-form-label" for="separate-label-input-outside-form">Label</label>
<input type="checkbox" id="separate-label-input-outside-form">
<label id="nested-input-outside-form-label">Label<input type="checkbox" id="nested-input-outside-form"></label>

<form>
<div class="ui-checkbox">
<label class="ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-checkbox-off">Pre-rendered</label>
<input type="checkbox" id="pre-rendered-label-test" data-nstest-enhanced="true">
</div>
</form>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/unit/checkboxradio/find_label_tests_core.js
@@ -1,3 +1,5 @@
$.mobile.ns = "nstest-";

var pairs = [
{
label: "#separate-label-outside-form-label",
Expand Down Expand Up @@ -49,3 +51,13 @@ test( "_findLabel() works correctly", function() {
": the label was correctly identified as (not?) the parent" );
}
});

test( "label on pre-rendered checkbox is found", function() {
var actualLabel = $( "#pre-rendered-label-test" )
.checkboxradio()
.data( "mobile-checkboxradio" ).label,
expectedLabel = $( "#pre-rendered-label-test" ).prev();

deepEqual( actualLabel.length, 1, "One label was found" );
deepEqual( actualLabel[ 0 ], expectedLabel[ 0 ], "The right label was found" );
});

0 comments on commit 9aa1f30

Please sign in to comment.