Reputation: 702
Our client need a custom design radio button style for the jQuery-mobile. Actually it's very similar to default jQuery-mobile radio button design in horizontal mode. For example jQuery-mobile define the horizontal radio button as
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>I like to buy and wear trendy must-haves</legend>
<input type="radio" name="radio-choice" id="radio-choice-1" value="choice-1" checked="checked" />
<label for="radio-choice-1">1</label>
<input type="radio" name="radio-choice" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">2</label>
<input type="radio" name="radio-choice" id="radio-choice-3" value="choice-3" />
<label for="radio-choice-3">3</label>
<input type="radio" name="radio-choice" id="radio-choice-4" value="choice-4" />
<label for="radio-choice-4">4</label>
<input type="radio" name="radio-choice" id="radio-choice-5" value="choice-5" />
<label for="radio-choice-5">5</label>
</fieldset>
Additionally our client wants to display the default radio button below the lablel
. For example following image
I would like to know does jQuery-mobile allow us to display the default radio buttons ? If so can you give an example ?
Or should we need to customize this ?
Upvotes: 2
Views: 8730
Reputation: 3612
No css or javascript necessary; it's a matter of which elements and classes you use, e.g:
<div id="test_content" class="ui-content" data-role="main" data-theme="b">
<fieldset class="ui-controlgroup ui-corner-all">
<div class="ui-grid-b ui-controlgroup-controls" style="width: 560px;">
<div class="ui-block-a">
<input name="invoicing_filter_type" id="invoicing_filter_tobeinvoiced"
value="1|4" type="radio" data-mini="true" data-iconpos="bottom">
<label for="invoicing_filter_tobeinvoiced">To be invoiced</label>
</div>
<div class="ui-block-b">
<input name="invoicing_filter_type" id="invoicing_filter_pending"
value="9|5" type="radio" data-mini="true" data-iconpos="bottom">
<label for="invoicing_filter_pending">Invoices pending</label>
</div>
<div class="ui-block-b">
<input name="invoicing_filter_type" id="invoicing_filter_tobereleased"
value="9|6" type="radio" data-mini="true" data-iconpos="bottom">
<label for="invoicing_filter_tobereleased">Invoices to be released</label>
</div>
</div>
</fieldset>
</div>
Note that data-role is NOT used here. Corresponding fiddle
Upvotes: 2
Reputation: 57309
First thing, it can't be done through the jQM configuration. This must be created manually through a jquery (like any other jQM widget, including fieldset).
I have created an working example for you: http://jsfiddle.net/Gajotres/779Kn/
Your only need to do one more thing, I didn't want to bother with a custom images so I am using images created for my other example: https://stackoverflow.com/a/13634738/1848600
Here's an javascript needed:
$(document).on('pagebeforeshow', '#index', function(){
$('<div>').addClass('checkBox').appendTo('fieldset div div.ui-radio label');
$('input[type="radio"]').each(function(){
($(this).is(':checked')) ? $(this).next().find(".checkBox").addClass('checked') : $(this).next().find(".checkBox").addClass('not-checked');
});
$(document).on('click', '.ui-radio', function(){
$('input[type="radio"]').each(function(){
$(this).next().find(".checkBox").addClass('not-checked').removeClass('checked');
});
if($(this).find('input[type="radio"]').is(':checked')){
$(this).find('label div.checkBox').removeClass('checked').addClass('not-checked');
$(this).find('input[type="radio"]').attr('checked' , false);
} else {
$(this).find('label div.checkBox').removeClass('not-checked').addClass('checked');
$(this).find('input[type="radio"]').attr('checked' , true);
}
});
});
Here's css:
.checkBox{
width: 18px;
height: 18px;
background: #d9d9d9;
border-radius: 3px;
margin: 0 auto;
margin-bottom: 5px;
}
.not-checked, .checked {
background-image: url("http://www.fajrunt.org/icons-18-white.png");
background-repeat: no-repeat;
}
.not-checked {
background-position: -18px 0;
background-color:#d9d9d9;
}
.checked {
background-position: -720px 0;
background-color:#6294bc;
}
If you can wait few hours I will update a picture, I can't do it from my current location.
If you want to find more about how to customize jQuery Mobile page and widgets then take a look at this article. It comes with a lot of working examples, including why is !important necessary for jQuery Mobile.
Upvotes: 4
Reputation: 6160
Is this what you are looking for
Using CSS
.myclass2 {
background-color: yellow;
float: left;
margin-top: 11px;
}
.myclass {
background-color: yellow;
float: left;
left: 13px;
margin-top: 26px;
padding-left: 22px;
position: relative;
top: 10px;
}
Upvotes: 0