Skip to Content
Menu
This question has been flagged
3 Replies
7425 Zobrazenia

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
Zrušiť
Best Answer


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
Zrušiť
Best Answer

it will work without js ?


Avatar
Zrušiť
Best Answer

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
Zrušiť
Related Posts Replies Zobrazenia Aktivita
0
sep 22
803
1
apr 21
5414
1
jan 19
4210
1
júl 15
3760
0
nov 24
640