跳至內容
選單
此問題已被標幟
2 回覆
9544 瀏覽次數

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.

頭像
捨棄
作者 最佳答案

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)"/>
頭像
捨棄
最佳答案

<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.

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??

相關帖文 回覆 瀏覽次數 活動
4
12月 15
6246
1
9月 23
4971
1
3月 15
4645
2
9月 23
8822
0
10月 24
1172