简体   繁体   中英

How to trigger onchange method when field is being filled from JavaScript?

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.

Jquery on method can bind the event to your selector:

 $(selector).on(event,function)

ex:

('#id').on('change',function(){
   // do your logic....
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM