[FIX] website: enable to use addCustomField function with more types

The goal of this commit is to be able to use the `addCustomField`
function with a `type` argument that is different of `checkbox`,
`radio` or `select`.

opw-3246341

X-original-commit: 34b3770ad1ee9c872acaf4f82ac3c6cf52d5d333
Part-of: odoo/odoo#122782
This commit is contained in:
Louis (loco)
2023-05-30 13:03:42 +02:00
parent 2dac9e6851
commit cd82c87159
@@ -46,7 +46,9 @@
trigger: `we-select we-button[${data}]`,
}];
};
const addField = function (data, name, type, label, required, display = {visibility: VISIBLE, condition: ''}) {
const addField = function (name, type, label, required, isCustom,
display = {visibility: VISIBLE, condition: ""}) {
const data = isCustom ? `data-custom-field="${name}"` : `data-existing-field="${name}"`;
const ret = [{
content: "Select form",
extra_trigger: 'iframe .s_website_form_field',
@@ -88,7 +90,8 @@
}
if (type !== 'checkbox' && type !== 'radio' && type !== 'select') {
let inputType = type === 'textarea' ? type : `input[type="${type}"]`;
testText += `:has(${inputType}[name="${name}"]${required ? '[required]' : ''})`;
const nameAttribute = isCustom && label ? label : name;
testText += `:has(${inputType}[name="${nameAttribute}"]${required ? "[required]" : ""})`;
}
ret.push({
content: "Check the resulting field",
@@ -98,10 +101,10 @@
return ret;
};
const addCustomField = function (name, type, label, required, display) {
return addField(`data-custom-field="${name}"`, name, type, label, required, display);
return addField(name, type, label, required, true, display);
};
const addExistingField = function (name, type, label, required, display) {
return addField(`data-existing-field="${name}"`, name, type, label, required, display);
return addField(name, type, label, required, false, display);
};
wTourUtils.registerWebsitePreviewTour("website_form_editor_tour", {