Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4764 Представления

Can anyone explain how are inputs on the template website_sale.address set as required? I need to make zip required but cannot figure out what method is used. I don't see anything in template controller or I haven't found anything in js files.


<div t-attf-class="form-group #{error.get('phone') and 'o_has_error' or ''} col-lg-6" id="div_phone">

    <label class="col-form-label" for="phone">Phone</label>

    <input type="tel" name="phone" t-attf-class="form-control #{error.get('phone') and 'is-invalid' or ''}" t-att-value="'phone' in checkout and checkout['phone']" />

</div>


<t t-set='zip_city' t-value='country and [x for x in country.get_address_fields() if x in ["zip", "city"]] or ["city", "zip"]'/>

<t t-if="'zip' in zip_city and zip_city.index('zip') &lt; zip_city.index('city')">

    <div t-attf-class="form-group #{error.get('zip') and 'o_has_error' or ''} col-md-4 div_zip">

        <label class="col-form-label label-optional" for="zip">Zip Code</label>

        <input type="text" name="zip" t-attf-class="form-control #{error.get('zip') and 'is-invalid' or ''}" t-att-value="'zip' in checkout and checkout['zip']" />

    </div>

</t>

Phone input is required, zip is not. How is it done?

Аватар
Отменить
Лучший ответ

Hi Samo,

You can set required by inherit website_sale controller -> main.py

Here we got 2 function:
_get_mandatory_billing_fields
_get_mandatory_shipping_fields

Just add your field name that you wish to make it required


Regards,
Ivan

Аватар
Отменить
Автор

thanks!

Автор

I've extended the controller but it doesn't work. It still isn't mandatory!

What Odoo version did you use ?

Автор

odoo 12 CE. I've even extended the template input field name="field_required" with zip

You've restarted your server right ?

I tried & it works from my side, you may need to try & print the variable in checkout_form_validate function

Автор

yeah, I've restarted the server. I've extended the controller:

from odoo.addons.website_sale.controllers.main import WebsiteSale

class TablaWebsiteSale(WebsiteSale):

def _get_mandatory_billing_fields(self):

return ["name", "email", "street", "city", "zip", "country_id"]

def _get_mandatory_shipping_fields(self):

return ["name", "street", "city", "zip", "country_id"]

But when I log the output of those methods

I get only: odoo.addons.website_sale.controllers.main: mandatory shipping: ['name', 'street', 'city', 'country_id'], mandatory billing: ['name', 'email', 'street', 'city', 'country_id']

I think you also need to inherit "checkout" and "checkout_form_validate" function, because these 2 functions call for it

Автор

Ok now it works, thanks.... but weird I never needed to inherit other methods.

Glad it works!

Related Posts Ответы Просмотры Активность
5
окт. 23
15953
0
мая 23
1637
0
февр. 22
2226
0
февр. 21
2691
0
июн. 20
2463