diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 1244773ff3a..60fe9f4072e 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -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. diff --git a/addons/website/static/src/snippets/s_website_form/options.js b/addons/website/static/src/snippets/s_website_form/options.js index 52528e34b1d..db3f981dcdb 100644 --- a/addons/website/static/src/snippets/s_website_form/options.js +++ b/addons/website/static/src/snippets/s_website_form/options.js @@ -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, }; diff --git a/addons/website/static/tests/tours/website_form_editor.js b/addons/website/static/tests/tours/website_form_editor.js index ae256e4eb5f..9961d238707 100644 --- a/addons/website/static/tests/tours/website_form_editor.js +++ b/addons/website/static/tests/tours/website_form_editor.js @@ -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 () {}, }, diff --git a/addons/website/static/tests/tours/website_form_editor_frontend.js b/addons/website/static/tests/tours/website_form_editor_frontend.js index 4369b0249f2..179e343bf5f 100644 --- a/addons/website/static/tests/tours/website_form_editor_frontend.js +++ b/addons/website/static/tests/tours/website_form_editor_frontend.js @@ -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'] ]], });