跳至内容
菜单
此问题已终结
2 回复
5629 查看

Dears,

I am creating a website with Odoo 10.

I am testing the address form and I noticed that City/Email/Country/Name are mandatory but not the zip code.

How should I proceed to make this field required and check while submitting the form?

1- create my own template with inheritance to website.sale.address template in template.xml and change the style

2- do I have to change the python code and add 'zip'  in the fields to be filled?

Anything else?

Many thanks for your help

Redgy

形象
丢弃
最佳答案

The first way is the way to go. Inherit the corresponding website template and adapt it to your requirement. See the original code using the HTML/CSS website editor to learn the differences between mandatory and non-mandatory fields and look at the following example I have made to make the phone number mandatory and the company name not mandatory in the website contactus template. It may give the idea:

<odoo>
  <data>
  <template name= "tw Website Contact Private" id="tw_website_contactus_private.contactus_form" inherit_id="website_crm.contactus_form">
  <xpath expr="//div[label[@for='phone']]" position="replace">
  <div class="form-group form-field o_website_form_required_custom">
  <label class="col-md-3 col-sm-4 control-label" for="phone">Phone Number</label>
  <div class="col-md-7 col-sm-8">
  <input type="text" class="form-control o_website_form_input" name="phone" required="" t-att-value="request.params.get('phone', '')"/>
  </div>
  </div>
  </xpath>
  <xpath expr="//div[label[@for='partner_name']]" position="replace">
  <div class="form-group form-field">
  <label class="col-md-3 col-sm-4 control-label" for="partner_name">Your Company</label>
  <div class="col-md-7 col-sm-8">
  <input type="text" class="form-control o_website_form_input" name="partner_name" t-att-value="request.params.get('partner_name', '')"/>
  </div>
  </div>
  </xpath>
  </template>
  </data>
</odoo>

Make a simple module with that and adapt it to your requirement. In your case it might be enough to remove the label class "label-optional" , if not, this might also help: https://www.odoo.com/forum/help-1/question/custom-forms-in-website-builder-84171

形象
丢弃
编写者 最佳答案

Hi Ermin,

It works. I have removed the label-optional and added "required".

What's not clear to me, the other mandatory field do not have this "required" in the template description.

Many thanks

形象
丢弃

Maybe because the field is mandatory in the model's python file without declaring it in the "Template" file