I have some HTML that I'm generating using JS on the client side. I'd still like to apply the style and functionality of jQuery Mobile UI to those objects as well. I can't seem to figure out how though...
Say I generate a:
<div data-role="fieldcontain">
<label for="select-choice-1" class="select">Choose shipping method:</label>
<select name="select-choice-1" id="select-choice-1">
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>
And want to render it via jQuery Mobile UI inside a page... how would one do that?
I know with standard jQuery UI I'd just have to make a call along the lines of:
$("#select-choice-1").buttonset();
Is there something like this for jQuery Mobile UI?
I have some HTML that I'm generating using JS on the client side. I'd still like to apply the style and functionality of jQuery Mobile UI to those objects as well. I can't seem to figure out how though...
Say I generate a:
<div data-role="fieldcontain">
<label for="select-choice-1" class="select">Choose shipping method:</label>
<select name="select-choice-1" id="select-choice-1">
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>
And want to render it via jQuery Mobile UI inside a page... how would one do that?
I know with standard jQuery UI I'd just have to make a call along the lines of:
$("#select-choice-1").buttonset();
Is there something like this for jQuery Mobile UI?
Share asked Jan 12, 2011 at 19:15 SerhiySerhiy 2,5553 gold badges34 silver badges49 bronze badges2 Answers
Reset to default 2UPDATE!
Yeah! The new implementation with event just landed!
http://jquerymobile./blog/2011/07/22/jquery-mobile-team-update-week-of-july-18th/
Now in beta2 there will be a create
event that triggered on an element will cause its rendering.
I will update the faq when beta2 ships.
Find the topmost element you add to DOM and call .page()
on it.
This question in fact duplicates a lot of other questions tagged jquery-mobile, therefore I created a shot tutorial not to describe it again every time.
See first post here: http://jquerymobiledictionary.dyndns/faq.html
If called upon pagecreate
$('#page').live('pagecreate',function(event){
$('#elem_container').page();
});
you go for a recursive loop ride. I wrote my own enhance() function to take care of this issue.
$('#page').live('pagecreate',function(event){
enhance($('#elem_container'));
});
The function is basically just condensed the code below...
function enhance(dis){
dis.find( "[type='radio'], [type='checkbox']" ).checkboxradio();
dis.find( "button, [type='button'], [type='submit'], [type='reset'], [type='image']" ).not( ".ui-nojs" ).button();
dis.find( "input, textarea" ).not( "[type='radio'], [type='checkbox'], button, [type='button'], [type='submit'], [type='reset'], [type='image']" ).textinput();
dis.find( "input, select" ).filter( "[data-role='slider'], [data-type='range']" ).slider();
dis.find( "select:not([data-role='slider'])" ).selectmenu();
}
Older Post:
After digging around the jQuery mobile file I finally figured it out... quite easy actually...
$("#select-choice-3").selectmenu();
And here's the chunk of code I dug this up in...
_enchanceControls: function() {
var o = this.options;
// degrade inputs to avoid poorly implemented native functionality
this.element.find( "input" ).each(function() {
var type = this.getAttribute( "type" );
if ( o.degradeInputs[ type ] ) {
$( this ).replaceWith(
$( "<div>" ).html( $(this).clone() ).html()
.replace( /type="([a-zA-Z]+)"/, "data-type='$1'" ) );
}
});
// enchance form controls
this.element
.find( "[type='radio'], [type='checkbox']" )
.checkboxradio();
this.element
.find( "button, [type='button'], [type='submit'], [type='reset'], [type='image']" )
.not( ".ui-nojs" )
.button();
this.element
.find( "input, textarea" )
.not( "[type='radio'], [type='checkbox'], button, [type='button'], [type='submit'], [type='reset'], [type='image']" )
.textinput();
this.element
.find( "input, select" )
.filter( "[data-role='slider'], [data-type='range']" )
.slider();
this.element
.find( "select:not([data-role='slider'])" )
.selectmenu();
}