How can I refresh my radio button

How can I refresh my radio button

Dear All,

I have a localStorage where an information about a mode is stored.
mode can be "gps" or "phone"

I am extracting the information and then I need to "update" a radio button which look like
  1. <form id="edit-perimetre" action="" method="post" data-ajax="true" class="ui-body ui-body-d ui-corner-all ui-shadow">           
           
              <label for="perimetre-edit">Perimètre (mètre)</label>
               <input type="text" id="perimetre-edit" name="code" class="validate[required,custom[number]]">
                
             <fieldset data-role="controlgroup" data-mini="true">
             <legend>Mode</legend>
                        <input type="radio" name="mode" id="perimetre-edit-gps" value="gps" />
                        <label for="perimetre-edit-gps">Point fixe</label>
               
                        <input type="radio" name="mode" id="perimetre-edit-phone" value="phone"/>
                        <label for="perimetre-edit-phone">Téléphone</label>
               
                </fieldset>
    </form>













I am extracting the value of the mode like this (it works)
  1. var tplFormMode    = '{{mode}}';
    var mode = Mustache.to_html(tplFormMode, moduleData);
Then I have to update my radio button and I am using the function .checkboxradio('refresh'), but it does not work. Here is my code:
  1. var tplFormMode    = '{{mode}}';
    var mode = Mustache.to_html(tplFormMode, moduleData);

    //This check the input and remove the checked attribute
        $('#perimetre #edit-perimetre').find( 'input[name="mode"]' ).attr('checked',false);
    // This put back the checked attribut to the input matching to the var mode.
        $('#perimetre #edit-perimetre #perimetre-edit-'+mode).attr('checked',true);
    // And then I am trying to update the radio button
        $('#perimetre #edit-perimetre input[type="radio"]').checkboxradio('refresh');







Be informed that it work when I refresh my page.
But it does not work in that case:
  1. When I click on "Toto" who have a GPS, it slide to the second page, and the GPS radio buton is checked.
  2. Then, I click the back button
  3. Then I click on "Titi" who have a phone. it slode to the second page, and the GPS is still checked, while it should be phone.
  4. Finally, when I press F5, the phone is checked instead of GPS
How can I adapt my code to have radio buttons updated, when I click "Titi" or "Toto".
I though that the checkboxradio('refresh'); will help.

Many thank for your help
Cheers














    • Topic Participants

    • forum