Permalink
Browse files

Checkboxradio: When pre-rendered, assume label is a sibling of the input

(cherry picked from commit cb7a5dc)

Closes gh-7471
Fixes gh-7470
  • Loading branch information...
1 parent 05f409d commit 9aa1f30f4df50df79461d864b613461e4cc1aa0b @gabrielschulhof gabrielschulhof committed Jun 4, 2014
@@ -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";
@@ -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>
@@ -1,3 +1,5 @@
+$.mobile.ns = "nstest-";
+
var pairs = [
{
label: "#separate-label-outside-form-label",
@@ -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.