0

Here's the html:

<form>
    <fieldset data-role="controlgroup" data-type="horizontal" id="buddies" />
</form>

Here's the javascript:

for (var i = 0; i < json.length; i++) {
    var usr = json[i];
    var mid = usr.mid;
    var input = '<input id="' + mid + '" type="checkbox"';
    var photo = usr.photo;
    if (typeof photo === 'undefined') {
    photo = '<span class="middle"></span><br/>';
    no_photo_ids[no_photo_ids.length] = mid;
    } else {
    photo = '<span class="middle"><img src="' + photo + '"/></span><br/>';
    if (max_invite_messages-- > 0) {
        input += ' checked="checked"';
    }
    }
    input += '>';
    var label = '<label for="' + mid + '">' + photo + usr.name + '</label>';
    $('#buddies').append(input);
    $('#buddies').append(label);
}
$('#buddies').trigger('create');

It works all right in jquery mobile 1.3.2, just like: enter image description here

But it messed up in 1.4.3, just like: enter image description here

Omar
  • 32,302
  • 9
  • 69
  • 112
jon doe
  • 443
  • 1
  • 4
  • 9
  • It seems like it is something else in your code that changed bc the documentation does not suggest that this setup has deprecated. It looks like your var input is missing a ">" at the end though. This might be creating an issue. – tylerlindell Aug 11 '14 at 05:34
  • possible duplicate of [Control group loses control after dynamic add of radio button - jQuery Mobile](http://stackoverflow.com/questions/21059478/control-group-loses-control-after-dynamic-add-of-radio-button-jquery-mobile) – Omar Aug 30 '14 at 21:45

1 Answers1

0

Finally I found a solution: Control group loses control after dynamic add of radio button - jQuery Mobile

1.3.2 is easy to work like this:

$('#buddies').append(...);
$('#buddies').append(...);
...
$('#buddies').trigger('create'); 

1.4.3 is much a mess like this:

$('#buddies').controlgroup("container").append(...);
$('#buddies').controlgroup("container").append(...);
...
$('#buddies').enhanceWithin().controlgroup("refresh");

Now it works pretty good:

enter image description here

Community
  • 1
  • 1
jon doe
  • 443
  • 1
  • 4
  • 9