Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
7528 Visualizzazioni

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
Abbandona
Risposta migliore


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
Abbandona
Risposta migliore

it will work without js ?


Avatar
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
set 22
803
1
apr 21
5525
1
gen 19
4289
1
lug 15
3881
0
nov 24
761