1

Problem is very simple. I am using certain API which is called when I click a button and some of the fields are being filled from a widget that I created

I use that widget at multiple places in my system

The problem is that when those fields are filled I need

@api.onchange('exmplple')

method to trigger them, but it doesn't (I would say it's a bug).

What would be the workaround or solution to trigger that method when those fields change whenever my widget works?

Update:

Sorry for the confusion that my question caused. I will try to explain what exactly I was thinking and why I only have tried server side things so far. The problem is that in any other situation python code api.onechange would work completely fine.

    @api.onchange
    def do_smth_when_country_changes(self):
            if country_id = 133
                    self.lang = 'pl_PL'
            elif:
                    .......more ifs

But I have fields which are filled from google maps (JavaScript code that I wrote).

            <field name='autocomplete' widget='gmap_autocomplete' country_id='country_id'>
            <field name='country_id'>

Here when i search for address with autocomplete field, and i click on one, country_id field will be filled with country. And Also there are some other field has to change value whenever country_id changes (for example res.partner field lang).

    <field name='lang'/>

Since Python onchange method doesn't trigger country_id field I though that JavaScript would probably only thing that would solve my problem. So What I want to do is to access field coutry_id in specific form view (let's say only in view_partner_form) and when it changes access value of lag field and change it as well.

enigmq
  • 393
  • 5
  • 19
  • You can use "on" function of jquery on dynamic values. documentation :http://api.jquery.com/on/ – Suresh Kamrushi Jun 21 '17 at 10:56
  • 1
    Possible duplicate of [How do I programmatically force an onchange event on an input?](https://stackoverflow.com/questions/136617/how-do-i-programmatically-force-an-onchange-event-on-an-input) – Chirag Ravindra Jun 21 '17 at 10:56
  • hey @enigmq could you please provide a code example of what you have tried so far? – Hayko Koryun Jun 21 '17 at 10:56
  • Hi @Hayko Koryun As I mentioned, what I have tried was doing it with api.onchange, but it does't work. I also tried doing it with api.depends, this method does work after you click save, but it would be perfect if it triggered immediately after fields are being filled. – enigmq Jun 21 '17 at 11:07
  • binding the event with $(document).on('change','selector',callback) might help you. – Suraj Khanal Jun 21 '17 at 11:08
  • I think what happens here, you guys are giving good answers, but Odoo framework probably requires something more specific to do such things – enigmq Jun 21 '17 at 11:52
  • Please give us a better example with code. You're mixing Odoo's python API with the JS Client. It's hard to understand what you're trying to do and what you've tried so far with example code. – CZoellner Jun 21 '17 at 13:41
  • 3
    Yes @CZoellner is correct, I think there is confusion between the client side 'change' event and the server side 'onchange' bindings. I have not done something like this but it might be worth learning how Odoo's js framework triggers the server side onchange functions and learning how to trigger this within your js code. If you do not want to do that. Create a method on the server and use javascript `new Model('your_addon.model_name').call('onchange_method_name',[args_here])` to forcibly trigger the server side onchange. – Phillip Stack Jun 21 '17 at 19:11
  • Thanks for your answer @Phillip Stack. I tried to add some information of what I want to do. And also new Model('your_addon.model_name').call('onchange_method_name',[‌​args_here]) This was something interesting to look at, I would like to read about it more, for example how do I call that method only when I am at specific form and so on. Could you recommend any nice documentation or even tutorial about this? – enigmq Jun 22 '17 at 06:05
  • Hello did you find a solution for this.... I'm having the exact same issue here – aafirvida Aug 02 '19 at 21:37

0 Answers0