Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
27198 Lượt xem

I added a few custom fields to the recruitment module in odoo 10. I also changed the frontend view (website_hr_recruitment_templates.xml) in order to let the applicant fill in the fields.

For fields.Char this was easy, but I have a few selection fields as well. How can I create a drop-down field on the frontend?

Thank you very much.

Ảnh đại diện
Huỷ bỏ

How i can do the same, for many2many field, using something like multiple in

Thank you very much.

Tác giả Câu trả lời hay nhất

I figured it out myself:


 <select class="form-control" name="category">
     <t t-foreach="categories" t-as="category">
          <option t-attf-value="#{category.id}"><t t-esc="category.name"/></option>
     </t>
 </select>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

@p.n1@gmx.net answered is useful to implement the Many2one field.

But in the case of Selection field, Try this

your_field = fields.Selection([('sale', 'Sales'), ('purchase', 'Purchases'), ('none', 'None')])
 <select class="form-control" name="your_field">
       <option t-attf-value="'sale'">Sales</option>
       <option t-attf-value="'purchase'">Purchases</option>
       <option t-attf-value="'none'">None</option>
 </select>

Thanks 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

By doing following you can add a selection field into the frontend.

<select name="your_field" id="your_field_id"


        style="width:290px; height:45px"


        class="advanced-select">


    <t t-foreach='your_field' t-as="field" >


        <option t-esc='field.name' t-att-value="field.id"/>


    </t>


</select>


Regards

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

@ Ajay

<select class="form-control" name="category">
     <t t-foreach="categories" t-as="category">
          <option t-attf-value="#{category.id}" t-att-selected="WHATEVER_CATEGORY_ID_YOU_WANT_TO_HAVE_SELECTED"><t t-esc="category.name"/></option>
     </t>
 </select>

Just add the t-att-selected attribute and give it the value you want to have selected from your otions

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

@Shameem 

Your answer is working, but how to populate the field with the already selected value.

Please help me with this.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 22
6929
0
thg 7 20
3324
2
thg 10 16
7160
1
thg 12 23
8504
0
thg 11 23
1493