Reputation: 265
I have been trying to insert a checkbox(not the normal checkbox) that has all jquery mobile css features in a listview along with a data-icon. Is it possible to do something like below?
I have been trying like below.
<ul data-role="listview">
<li>
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
<a href="#page4"><h3>Task 1</h3><p>Lorem ipsum order no have may not be</p></a></li>
<li>
<a href="audi.html"><h3>Task 2</h3><p>Lorem ipsum order no have may not be</p></a></li>
<li>
<a href="bmw.html"><h3>Task 3</h3><p>Lorem ipsum order no have may not be</p></a></li>
<li>
<a href="acura.html"><h3>Task 4</h3><p>Lorem ipsum order no</p></a></li>
</ul>
But i get something like this,With no css styles for checkbox. Plz help on this.
Upvotes: 0
Views: 5135
Reputation: 1366
Duplicate of this: Check this fiddle with check box in list view included with data-icon.
http://jsfiddle.net/ek2QT/184/
markup:
<ul data-role="listview" data-theme="c" data-dividertheme="d">
<li>
<div class="checkBoxLeft">
<input type="checkbox" name="checkbox-0" id="checkbox-0" class="hidden-checkbox"/>
</div>
<a href="#" class="detailListText">Message 1 </a>
</li>
<li>
<div class="checkBoxLeft">
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="hidden-checkbox" checked="checked" />
</div>
<a href="#" class="detailListText">Message 2 </a>
</li>
</ul>
Code:
$('#index').live('pagebeforeshow',function(e,data){
$('input[type="checkbox"]').each(function(){
($(this).is(':checked')) ? $(this).parent().parent().addClass('checked') : $(this).parent().parent().addClass('not-checked');
});
});
$('.checkBoxLeft').bind('click', function(e) {
if($(this).find('input[type="checkbox"]').is(':checked')){
$(this).removeClass('checked').addClass('not-checked');
$(this).find('input[type="checkbox"]').attr('checked' , false);
} else {
$(this).removeClass('not-checked').addClass('checked');
$(this).find('input[type="checkbox"]').attr('checked' , true);
}
});
CSS:
.detailListText{
margin: 0 0 0 20px;
}
.checkBoxLeft{
position: absolute;
left: 10px;
top: 28%;
width: 18px;
height: 18px;
background: #d9d9d9;
border-radius: 3px;
}
.hidden-checkbox {
display: none;
}
.not-checked, .checked {
background-image: url("http://www.dragan-gaic.info/elements.png");
background-repeat: no-repeat;
}
.not-checked {
background-position: 18px 0;
background-color:#d9d9d9;
}
.checked {
background-position: 0 0;
background-color:#6496bc;
}
Upvotes: 3
Reputation: 3075
Look at the icon position example at http://view.jquerymobile.com/1.3.2/dist/demos/widgets/checkbox/
The checkboxes need to be wrapped in a label, which you can then style
You can see in this http://jsfiddle.net/peter/ckWDG/
That the checkbox with a label renders correctly while the one without a label looks like a regular html checkbox.
<ul data-role="listview">
<li>
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="" />
<a href="#page4"><h3>Task 1</h3><p>Lorem ipsum order no have may not be</p></a></li>
<li>
<a href="audi.html"><h3>Task 2</h3><p>Lorem ipsum order no have may not be</p></a></li>
<li>
<a href="bmw.html"><h3>Task 3</h3><p>Lorem ipsum order no have may not be</p></a></li>
<li>
<a href="acura.html"><h3>Task 4</h3><p>Lorem ipsum order no</p></a> <label>
<input type="checkbox" name="checkbox-0 ">
</label></li>
</ul>
Upvotes: 0