1

I've got a html page with 2 checkboxradios. There's a button which should remove all radio buttons and load new ones through ajax.

I've got everything working, but there's a small problem with the css. This is what my radio buttons look like when opening the page: enter image description here

This is what it looks like, after I removed the radios and loaded new ones through AJAX: enter image description here

My HTML looks like this:

<div data-role="fieldcontain">
    <fieldset data-role="controlgroup" id="campaignselection">
    <input type="radio" name="campaign" id="autosalon_genf_2015" value="autosalon_genf_2015" checked="checked">
    <label for="autosalon_genf_2015">Autosalon Genf</label>
    <input type="radio" name="campaign" id="auto_zuerich_2014" value="auto_zuerich_2014">
    <label for="auto_zuerich_2014">Auto Zürich</label>
</fieldset>

And this is the jQuery part that does the update:

$("#updatevalues").click(function() {
// Download campaign codes
$.ajax({
    type: "GET",
    dataType: "json",
    url: 'http://hostname.com/api/directory',
    success: function(response) {
        // Remove all campaign entries from the current list
        $("#campaignselection").empty();
        $.each(response, function() {
            $("#campaignselection").append('<input type="radio" name="campaign" id="' + this.code + '" value="' + this.code + '" />');
            $("#campaignselection").append('<label for="' + this.code + '">' + this.label_de + '</label>');
            $("#" + this.code).checkboxradio();
            $("#" + this.code).checkboxradio("refresh");
        });

        //$("#campaignselection").trigger("create");
        //$("input[type='radio']").checkboxradio();
        //$("input[type='radio']").checkboxradio("refresh");
    }
});
})

Is there another method I have to execute? The version of jQuery mobile is 1.4.2.

Aravin
  • 4,126
  • 1
  • 23
  • 39
Ahatius
  • 4,777
  • 11
  • 49
  • 79
  • Add elements to `$("#campaignselection").controlgroup("container")` http://stackoverflow.com/a/20692597/1771795 – Omar Jun 28 '14 at 19:17
  • @Omar Thank you. I also had to change the object of the empty method to `.controlgroup("container")` but then it worked :) – Ahatius Jun 28 '14 at 20:30
  • Whether you add or remove, `.controlgroup("container")` is what you need ;) – Omar Jun 28 '14 at 20:58

0 Answers0