[FIX] web_editor, website: fix form custom fields starting with numbers
Before this commit, following this flow: - Add a form - Add a selection field - Add an option starting with a number - Save => The created form's option value is only the number From the website_form options, the options HTMLElement of a form field are generated using the field's records ids for their html element value attribute (see FormEditor._renderField). When [1] refactored the website_form options to use a generic ListUserValueWidget, the list records id computation changed to use parseInt instead of strings. This commit changes the detection of parsable int to match only strings that are made only of digits, and less than 16 of them so that their value is not lost. [1]: https://github.com/odoo/odoo/commit/9304f8fa7bb94f21dd4caa83f9679ffd1642691b opw-2980760 closes odoo/odoo#108248 X-original-commit: 166f4aa4d23a01901585b60d69fac47fe70b7ebe Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Signed-off-by: Benoit Socias (bso) <bso@odoo.com> Co-authored-by: Younn Olivier <yol@odoo.com>
This commit is contained in:
co-authored by
Younn Olivier
parent
e8d4c06300
commit
ae0253da40
@@ -2146,9 +2146,8 @@ const ListUserValueWidget = UserValueWidget.extend({
|
||||
if (this.el.dataset.idMode && this.el.dataset.idMode === "name") {
|
||||
id = el.name;
|
||||
}
|
||||
const idInt = parseInt(id);
|
||||
return Object.assign({
|
||||
id: isNaN(idInt) ? id : idInt,
|
||||
id: /^-?[0-9]{1,15}$/.test(id) ? parseInt(id) : id,
|
||||
name: el.value,
|
||||
display_name: el.value,
|
||||
}, el.dataset);
|
||||
@@ -2158,8 +2157,7 @@ const ListUserValueWidget = UserValueWidget.extend({
|
||||
this.selected = checkboxes.map(el => {
|
||||
const input = el.parentElement.previousSibling.firstChild;
|
||||
const id = input.name || input.value;
|
||||
const idInt = parseInt(id);
|
||||
return isNaN(idInt) ? id : idInt;
|
||||
return /^-?[0-9]{1,15}$/.test(id) ? parseInt(id) : id;
|
||||
});
|
||||
values.forEach(v => {
|
||||
// Elements not toggleable are considered as always selected.
|
||||
|
||||
@@ -1303,8 +1303,7 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({
|
||||
|
||||
list.dataset.hasDefault = ['one2many', 'many2many'].includes(type) ? 'multiple' : 'unique';
|
||||
const defaults = [...this.$target[0].querySelectorAll('[checked], [selected]')].map(el => {
|
||||
const idInt = parseInt(el.value);
|
||||
return isNaN(idInt) ? el.value : idInt;
|
||||
return /^-?[0-9]{1,15}$/.test(el.value) ? parseInt(el.value) : el.value;
|
||||
});
|
||||
list.dataset.defaults = JSON.stringify(defaults);
|
||||
|
||||
@@ -1391,10 +1390,9 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({
|
||||
options = [...multipleInputs.querySelectorAll('.checkbox input, .radio input')];
|
||||
}
|
||||
return options.map(opt => {
|
||||
const id = parseInt(opt.value);
|
||||
const name = select ? opt : opt.nextElementSibling;
|
||||
return {
|
||||
id: isNaN(id) ? opt.value : id,
|
||||
id: /^-?[0-9]{1,15}$/.test(opt.value) ? parseInt(opt.value) : opt.value,
|
||||
display_name: name.textContent.trim(),
|
||||
selected: select ? opt.selected : opt.checked,
|
||||
};
|
||||
|
||||
@@ -271,6 +271,22 @@ odoo.define('website.tour.form_editor', function (require) {
|
||||
}, {
|
||||
content: "Remove Germany Option",
|
||||
trigger: '.o_we_select_remove_option:eq(0)',
|
||||
}, {
|
||||
content: "Click on Add new Checkbox",
|
||||
trigger: 'we-list we-button.o_we_list_add_optional',
|
||||
}, {
|
||||
content: "Change last option label with a number",
|
||||
trigger: 'we-list table input:eq(3)',
|
||||
run: 'text 44 - UK',
|
||||
}, {
|
||||
content: "Check that the input value is the full option value",
|
||||
trigger: 'we-list table input:eq(3)',
|
||||
run: () => {
|
||||
const addedOptionEl = document.querySelector('iframe.o_iframe').contentDocument.querySelector('.s_website_form_field select option[value="44 - UK"]');
|
||||
if (!addedOptionEl) {
|
||||
console.error('The number option was not correctly added');
|
||||
}
|
||||
},
|
||||
}, {
|
||||
content: "Check the resulting snippet",
|
||||
trigger: "iframe .s_website_form_field.s_website_form_custom.s_website_form_required" +
|
||||
@@ -279,6 +295,7 @@ odoo.define('website.tour.form_editor', function (require) {
|
||||
":has(.s_website_form_select_item:contains('Belgium'))" +
|
||||
":has(.s_website_form_select_item:contains('France'))" +
|
||||
":has(.s_website_form_select_item:contains('Canada'))" +
|
||||
":has(.s_website_form_select_item:contains('44 - UK'))" +
|
||||
":not(:has(.s_website_form_select_item:contains('Germany')))",
|
||||
run: function () {},
|
||||
},
|
||||
|
||||
@@ -137,6 +137,11 @@ tour.register("website_form_editor_tour_submit", {
|
||||
content: "Check if conditional field is visible, it should.",
|
||||
trigger: "input[name='email_cc']",
|
||||
},
|
||||
{
|
||||
content: "Select state option",
|
||||
trigger: "select[name='State']",
|
||||
run: 'text 44 - UK',
|
||||
},
|
||||
{
|
||||
content: "Send the form",
|
||||
trigger: ".s_website_form_send"
|
||||
@@ -161,7 +166,7 @@ tour.register("website_form_editor_tour_results", {
|
||||
['email_to', '=', 'test@test.test'],
|
||||
['body_html', 'like', 'A useless message'],
|
||||
['body_html', 'like', 'Service : Development Service'],
|
||||
['body_html', 'like', 'State : Belgium'],
|
||||
['body_html', 'like', 'State : 44 - UK'],
|
||||
['body_html', 'like', 'Products : Xperia,Wiko Stairway']
|
||||
]],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user