0

i work with OpenERP 7 and i have 2 radio buttons that changes values of table. i have created an event wich call a python function that execute an sql query, after that i must reload the page to show the table whith new values. but the problem is that the radio buttons take the default value !! so the user will have only one choice, so i must set the default values of radio buttons after reloading the page. This is my Qweb code:

<t t-if="number === 2">
        <table  style="margin-left:360px;margin-top:0px;margin-bottom:0px;">
            <tr>
                <td style="text-align:left;font-size:12px;"><b>Jusqu'au mois courant:</b></td>
                <td>
                   <input type="radio" id="radio_budget_cumulee_jusque_mois_courant" value="courant" name="radio_budget_cumulee" checked="checked"/>

                </td> 
            </tr> 
             <tr>      
                 <td style="text-align:left;font-size:12px;"><b>Jusqu'au fin d'année:</b></td>
                <td>   
                   <input type="radio" id="radio_budget_cumulee_jusque_fin_anneee" value="fin" name="radio_budget_cumulee"/>
                </td> 
            </tr>
        </table>
       <div id="itkbudg"> 
        <div  t-attf-id="#{view.element_id}_action_#{column_index}_#{action_index}" class="oe_content" t-att-style="action.attrs.fold ? 'display: none;' : 'height: 220px;overflow-x: hidden;overflow-y: auto;padding: 0 12px 1px;'"></div>
        </div> 
    </t>

and this is my Javascript Code:

    $("#radio_budget_cumulee_jusque_mois_courant, #radio_budget_cumulee_jusque_fin_anneee").change(function(){


            est_jusqu_mois_courant=self.$el.find('#radio_budget_cumulee_jusque_mois_courant').is(':checked')
            est_jusqu_finannee=self.$el.find('#radio_budget_cumulee_jusque_fin_anneee').is(':checked')


            var mod=new instance.web.Model("itk.compta.dashboard");
            mod.call("itk_compta_dashboard_fct_changer_vue",[est_jusqu_mois_courant],{}).done(function(res) {



            });

            self.do_action({
                type: 'ir.actions.client',
                tag: 'reload',
        });



           // $radios.filter('[value=fin]').prop('checked', est_jusqu_finannee);
            //$radios.filter('[value=courant]').prop('checked', est_jusqu_mois_courant);


            //I tried to use this code
            var $radios = $('input:radio[name=radio_budget_cumulee]');
            $radios.filter('[value=fin]').attr('checked', est_jusqu_finannee);
            $radios.filter('[value=courant]').attr('checked', est_jusqu_mois_courant);
            // ANd i tried this code
            radiobtnmois_courant = document.getElementById("radio_budget_cumulee_jusque_mois_courant");
            radiobtnmois_courant.checked = false;

            radiobtnfin_anneee = document.getElementById("radio_budget_cumulee_jusque_fin_anneee");
            radiobtnfin_anneee.checked = true;

        });

But always the radio buttons takes the default values. Please any Help?

Kais Dkhili
  • 399
  • 1
  • 5
  • 18
  • On client side, you may have to use either localStorage or cookies to store the selected radio values. And, on page load, grad those values and set to your radios. – lshettyl Sep 14 '15 at 11:04

3 Answers3

2

Try <input type="radio" id="..." autocomplete="off" />

and try something like this in your script tag

$(document).ready(function(){
    $(".myradios").prop("checked", true); // true or false
});
Yon Glory
  • 76
  • 11
1

Why are you reloading the hole page again? A nicer way would be to reload the needed data via AJAX instead of the hole page. You can attribute the new values to your form via JQuery or even AngularJS

  • Hello Alexander yes you are right, i tried to do it but i haven't a solution check this question if you want :http://stackoverflow.com/questions/32561223/how-to-refresh-a-particular-div-in-a-page-that-contains-a-dashboard – Kais Dkhili Sep 14 '15 at 11:28
1

For radio buttons or checkboxes you can use .val() using an array of values.

$radios.val( [ ] ); // uncheck all radios
$radios.val( [ "fin" ] ); // check the radio with value "fin"
$radios.val( [ "courant" ] ); // check the radio with value "courant"
$radios.val( [ "fin", "courant" ] ); // not useful in radio button context, but you can use this for checkboxes
mrcgrtz
  • 71
  • 4