Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
7527 Ansichten

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
Verwerfen
Beste Antwort


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
Verwerfen
Beste Antwort

it will work without js ?


Avatar
Verwerfen
Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Sept. 22
803
1
Apr. 21
5521
1
Jan. 19
4288
1
Juli 15
3879
0
Nov. 24
756