Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
30373 มุมมอง

Hello, I want to make a handler for button in footer area using javascript. My view model looks below :

<record id="view_rnd_history_form" model="ir.ui.view">
<field name="name">rnd.history.form</field>
<field name="model">rnd.batch.record.history</field>
<field name="arch" type="xml">
<form string="History" version="7.0">
<group>
<field name="br_id" colspan="2"/>
<label for="start_date" string="Date"/>
<div>
<field name="start_date" class="oe_inline"/> -
<field name="end_date" class="oe_inline"/>
</div>
<field name="batch_number" colspan="2"/>
<field name="parameter_id" colspan="2"/>
</group>
<footer>
<button name="show_history" string="_Show" class="oe_highlight" onclick="alert('hello');"/>
</footer>
</form>
</field>
</record>

I'm confuse. the onclick attribute seem removed by qweb render process. I want a simple thing, user click on show_history button, then it call a simple javascript function or action client. Any information will be appreciate. Thank you.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I have created a module specifically to do this, you can found it in Odoo apps like "Soltein Button Widget"

The use of this module is like the following example:


<solt_button string="_Show">
    <code><![CDATA[
       jQuery('footer button:first').click(function() { alert('hello'); });
    ]]></code>
</solt_button>

In the code of the button you could access to the widget instance using self and also to the fields of the form using self.view.fields

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด
<form string="BlaBla">
<sheet>
<script>
YOUR JAVASCRIPT CODE HERE
</scrit>
YOUR XML CODE HERE
</sheet>
</form>


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I added javascript code like this :

...
...
...
<footer>
<button name="show_history" string="_Show" class="oe_highlight"/>
</footer>
<script>
jQuery('footer button:first').click(function() { alert('hello'); });
</script>

 The alert message never called after click the button. Well, I think it related on rendering process by qweb. The jQuery event handler is never attach to button node.  Is it possible to listen render event in qweb? Thanks.


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Odoo 12 JS custom_events แก้ไขแล้ว
1
ธ.ค. 19
9760
0
มี.ค. 17
8126
1
พ.ค. 25
758
2
เม.ย. 25
1338
0
มี.ค. 25
404