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

Hello,


I need to change values of field 2 depending on the selection of field 1.

Field 1: type

Field 2: category


<xpath expr="//div[2]" position="after">
<div class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="type">Type</label>
<div class="col-md-7 col-sm-8">
<select class="form-control" id="type" name="type">
<t t-foreach="types" t-as="cate">
<option t-attf-value="#{cate.id}">
<t t-esc="cate.name"/>
</option>
</t>
</select>
</div>
</div>
</xpath>
<xpath expr="//div[4]" position="replace">
<div class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="category">Category</label>
<div class="col-md-7 col-sm-8">
<select class="form-control" id="category" name="category" required="True">
<t t-foreach="category" t-as="cat">
<option>
<t t-esc="cat.name"/>
</option>
</t>
</select>
</div>
</div>
</xpath>


I would appreciate any explanation or example of how this type of action should be developed. Thank you
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Try the below code.

In JS:-

$(document).ready(function()
   {
       $("select[name='type']").change(function(){
            var $category = $("select[name='category']");
            $category.find("option:not(:first)").hide();
            var nb=$category.find("option[data-type_id="+($(this).val() || 0)+"]").show().length;
            $category.val(0);
})
})

In XML

https://ibb.co/VxzSY0Z

Regards

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
1956
1
พ.ค. 25
2039
QWeb: use t-if to check birthday date แก้ไขแล้ว
1
เม.ย. 25
2474
1
ก.พ. 25
1744
0
ต.ค. 24
1492