This question has been flagged
2 Replies
6951 Views
Avatar
Discard
Author

Seems the forum has some bugs, I was unable to enter text for the question. I'm on V8 so I'm after what has changed from V7 to V8. I have tried returning {'value' : {'fieldname etc... but the response that is returned to the client has another dictionary for 'value', with only some of the values changed in this onchange method.

Best Answer

Hi, try this for V8 onchange api.

    @api.onchange('field_name')
    def onchange_field_name(self):
        value = self.field_name if self.field_name else 'Nothing'
        return {'value': {'field_name': value}}

You can return the value in self itself like,

    @api.onchange('field_name')
    def onchange_field_name(self):
         self.message = "Dear %s" % (self.field_name or "")

Avatar
Discard
Author

The second approach works, but only for the field that triggered the onchange. If I want to update another field (a different column in a tree view) nothing happens. The first approach with the dictionary I'm not able to make work at all, I've looked at the response in Chrome and the values returned are the fields that have been modified in the onchange.

Best Answer

Hi,,

onchange method should return a dictionary in following format :-  Eg:

{

'warning': {'Your Message'},

'value': {'field_name1': VALUE , 'field_name2': VALUE, 'field_name3': VALUE}

}

Avatar
Discard