Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
7869 Tampilan

Odoo 12E on Ubuntu 18

Using a Form Builder snippet to build web forms (I've tried Form Builder and HTML Form Builder so far), and when I add a  dropdown (SELECT) form field for State, it returns every state from every country (not even in alphabetical order, see screenshot below).

Is there any way to filter these?  Specifically, to return only States in the United States?  Or States within whatever was picked in the Country dropdown?  I don't see anything within the Form Builder interfaces.



Avatar
Buang
Jawaban Terbai


By default in the website form builder, there is no option for add filter. 


But there is ready-made cold available for it if you want to implement it 
 https://www.odoo.com/my/account  
 there is state selection hide/show/filter based on the country 

related javascript code at: \https://github.com/odoo/odoo/blob/12.0/addons/portal/static/src/js/portal.js#L12

Avatar
Buang
Jawaban Terbai

it will work without js ?


Avatar
Buang
Jawaban Terbai

Hi,

Try like following

<select name="country_id" required="1">
    <t t-set="countries" t-value="request.env['res.country'].sudo().search([])"/>
    <t t-foreach="countries" t-as="country">
        <option t-att-value="country.id">
            <t t-esc="country.name"/>
        </option>
    </t>
</select>
<select name="state_id" required="1">
    <t t-set="state" t-value="request.env['res.country.state'].sudo().search([('country_id', '=', country_id)])"/>
    <t t-foreach="state" t-as="state">
        <option t-att-value="state.id">
            <t t-esc="state.name"/>
        </option>
    </t>
</select>


Regards

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Jul 25
6040
0
Sep 22
803
1
Jan 19
4632
1
Jul 15
4064
0
Nov 24
1006