Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
7274 Vistas

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
Descartar
Mejor respuesta


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
Descartar
Mejor respuesta

it will work without js ?


Avatar
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
sept 22
803
1
abr 21
5297
1
ene 19
4147
1
jul 15
3659
0
nov 24
540