Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

onChange event selection

By
karlos
on 9/12/13, 12:06 PM 2,502 views

Hi guys,

I'm trying to detect the event onchange from a selection field.

def onchange_changeday(self, cr, uid, ids, day_type, context=None):
    if day_type == "Complete":
        x = "09:00"
        return {'value':{'hour_begin': x }}

_columns = {
        'hour_begin':fields.char("Hour", size = 20),
        'day_type':fields.selection([('Complete', 'Complete'), ('Noncomplete', 'NonComplete')])
}

And then in the XML view I have:

<field name="hour_begin" placeholder="00:00" class="oe_inline_hour"/>
<field name="day_type" onchange="onchange_changeday(day_type)"/>

The goal was to whenever I change the selection to "Complete" it completes the field "hour_begin" with the value "09:00". I don't receive any errors, but it's not working either.

Thanks.

1
karlos
On 9/12/13, 1:14 PM

Solved.

def onchange_changeday(self, cr, uid, ids, day_type, context=None):
    if day_type:
        x = day_type
        if x == "Complete":
              return {'value':{'hour_begin': '09:00',},}
    return {'value': {}}

<field name="day_type" on_change="onchange_changeday(day_type, context)"/>
0

<field name="day_type" on_change="onchange_changeday(day_type)"/> .. you dont need to put context

Yes I do. In v7, you need to use context. I tried without it, and didn't work.

karlos
on 9/13/13, 6:53 AM

really?? im also using v7 and im not using context for my onchange and it is working for me.. Anyway what matter is it is working in a way we want it. Right??

Lady Sharmane Udtuhan
on 9/13/13, 7:19 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 9/12/13, 12:06 PM
Seen: 2502 times
Last updated: 3/16/15, 8:10 AM