Hello,
Sorry, I'm a casual developer, probably asking a stupid question...
I created a custom many2many field, called x_roles, link to partner.
I can use it from backend without any issue, but I want the website users to manage this field.
I added a multiple select input in the form:
And I modified the controller:
for field in set(['x_roles']) & set(values.keys()):
try:
values[field] = request.httprequest.form.getlist('x_roles')
except:
values[field] = False
Then I have a strange behavior. The first time all seems OK, selected values are saved and visible if I reload the form. But if I save again, all values are lost. In fact, at any try, only values that were not selected when loading the form, that I manually select, are actually saved. All others are reset (if any).
Any clue?
Sorry, can't copy the xml code un my post... Let's try in a comment:
<div t-attf-class="form-group #{error.get('x_roles’) and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="x_roles">Roles (multiselect)</label>
<select multiple="multiple" name="x_roles" t-attf-class="form-control #{error.get('x_roles’) and 'is-invalid' or ''}">
<t t-foreach="roles or []" t-as="role">
<option t-att-value="role.id" t-att-selected="role.id == int(x_roles) if x_roles else role.id in partner.x_roles.ids">
<t t-esc="role.x_name"/>
</option>
</t>
</select>
</div>