Odoo Website get multiple value of selection (multiple="multiple") or checkboxes

If you defined a selection on website form that will hold 'many2many' field, so it will look like 'many2many_tags' widget, you need a special handling on the controller backend.

By default, on the website form view you can select more than one value, but when you validated the form value sent to backend, it's only get the first value for this selection. Example code (xml):

<div id="group_permit" t-attf-class="form-group
   <label class="col-md-3 col-sm-4 control-label" for="permit" >Driving License</label>
   <div id="fields_permit" class="col-md-7 col-sm-8">
       <select multiple="multiple" name="permit_id" class="form-control select2">
          <t t-foreach="permit_ids" t-as="permit">
             <option t-att-value="permit.id">
             <t t-esc="permit.name"/>
             </option>
          </t>
       </select>
    </div>
</div>

On the 'firebugs', you can see there are two value for selection field was sent to server, example:

permit_id: 1
permit_id: 2

But On the backend, when you debug the value was sent only detected the first value.

{'permit_id': u'1'}


How to get all the value was selected?

We need extra code on the backend (controller) to handle it.

Example, when the form is submitted by POST method:

permit_ids = request.httprequest.form.getlist('permit_id')

or when it is by GET method:

permit_ids = request.httprequest.args.getlist('permit_id')

Then permit_ids will contain a list of selection or checkbox values.


 DO NOT CLICK THIS https://bit.ly/3biXWMc

Videos fill be uploaded regularly, so subscribe our youtube Channel.

Visit YouTube Channel http://youtube.com/odooindonesia

Untuk trik Odoo lainnya bisa cek Udemy courses http://udemy.com/user/akhmaddaniel

Visit official site http://vitraining.com

One Touch and Go Live with Odoo http://1toucherp.com

Twitter http://Twitter.com/akhdaniel 

Check our blog: http://indonesia.odoo.com


accounting,belajar erp,belajar odoo,business software,cloud computing,crm,dunia erp,enterprise resource planning,erp,erp software,erp system,event,inventory,it,it erp,mrp,odoo,odoo 11,odoo consultant indonesia,odoo erp,odoo indonesia,odoo tutorial bahasa indonesia,odoo tutorial indonesia,openerp,point of sales,pos,purchase,software as a service,tinyerp,tutorial odoo,tutorial odoo indonesia,odoo indonesia week,odoo indonesia payroll,odoo 13 indonesia
Odoo Website get multiple value of selection (multiple=&quot;multiple&quot;) or checkboxes
vitraining, odoo indonesia
16 May, 2020
Share this post
Archive
Sign in to leave a comment
Mass Mailing Contact Name