콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5003 화면

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!

관련 게시물 답글 화면 활동
5
10월 23
16381
0
5월 23
1851
0
2월 22
2496
0
2월 21
2952
0
6월 20
2672