So I'm trying to load dynamic content straight into my checkbox container (group_checkboxes)
<div id='group_checkboxes' data-role="fieldcontain">
</div>
This is the statement I'm running to populate the container:
$('#group_checkboxes').append('<fieldset data-role="controlgroup"><input type="checkbox" name="' + $(this).find('data').text() + '" class="custom" /><label for="' + $(this).find('data').text() + '">' + $(this).find('label').text() + '</label></fieldset>');
The checkboxes are all populated but the jQuery style is not applied.
According to the docs all I need to do is call this function to update the checkbox style...
$("input[type='checkbox']").checkboxradio("refresh");
That doesn't work though... Any idea what I'm doing wrong?
try
First try their own static demo code:
They are using just one fieldset as I mentioned in comments.
If this works, then adjust your script to generate the same markup dynamically and then refresh them
If this will work with their code, you will know that you have error in markup. If not, there is an error with that refresh function. (I know it's not final solution but you have to do a bit of debugging sometimes :)
Edit:
Found similar problems, solved by using
Page()
JQM FAQ
SO Question
When appending checkboxes or radio buttons to a controlgroup dynamically, you deal with two jQuery Mobile widgets,
.checkboxradio()
and.controlgroup()
.Both should be created/updated/enhanced/styled with jQuery Mobile CSS once new elements are added.
The way to achieve this is different in latest stable versions and RC version, but the methods are the same.
jQuery Mobile 1.2.x - 1.3.x (stable versions)
After appending checkbox / radio button to either a static or dynamic controlgroup,
.checkboxradio()
should be called first to enhance checkbox / radio button markup and then.controlgroup("refresh")
to re-style controlgroup div.jQuery Mobile 1.4.x
The only difference here is elements should be appended to
.controlgroup("container")
and then enhance both controlgroup and all elements within it, using
.enhanceWithin()
.What work out for me was to remove the whole fieldset then replace place a new fieldset with the new item I wanted to add then I called the
.trigger('pagecreate');
method on the whole page. This is not the most efficient solution but that is the only one that worked in my case.try with
$("#<id of fieldset controlgroup>").trigger("create");
http://jsfiddle.net/YKvR3/36/
It works just ones for me. Any idea why?
The Answer for me is: