[FIX] website: fix conditional visibility based on file upload
At the moment, if we try to make a website field conditionally visible based on whether a file has been uploaded, the field never appears even after uploading the file. Steps to reproduce issue - Create a new fresh DB with the website app. - Go to the Contact Us page, click on 'Edit'. - Add a File Upload field - Add another field, and set it to be conditionally visible on the File Upload field. Fix: - Create visibility comparators for files (fileSet / !fileSet), which check whether the `value.name` property is set / not set. opw-2856054 closes odoo/odoo#93756 X-original-commit: fec02f6cfc4abd68f0d6bd49285580510fe59465 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Signed-off-by: Antoine Dupuis (andu) <andu@odoo.com>
This commit is contained in:
@@ -545,6 +545,10 @@ odoo.define('website.s_website_form', function (require) {
|
||||
return value >= comparable;
|
||||
case 'less or equal':
|
||||
return value <= comparable;
|
||||
case 'fileSet':
|
||||
return value.name !== '';
|
||||
case '!fileSet':
|
||||
return value.name === '';
|
||||
}
|
||||
// Date & Date Time comparison requires formatting the value
|
||||
if (value.includes(':')) {
|
||||
|
||||
@@ -1162,6 +1162,8 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({
|
||||
return dependencyEl && dependencyEl.dataset.target && dependencyEl.dataset.target.includes('#datepicker');
|
||||
case 'hidden_condition_datetime_opt':
|
||||
return dependencyEl && dependencyEl.dataset.target && dependencyEl.dataset.target.includes('#datetimepicker');
|
||||
case 'hidden_condition_file_opt':
|
||||
return dependencyEl && dependencyEl.type === 'file';
|
||||
case 'hidden_condition_opt':
|
||||
return this.$target[0].classList.contains('s_website_form_field_hidden_if');
|
||||
case 'char_input_type_opt':
|
||||
@@ -1256,6 +1258,8 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({
|
||||
} else if (['text', 'email', 'tel', 'url', 'search', 'password', 'number'].includes(dependencyEl.type)
|
||||
|| dependencyEl.nodeName === 'TEXTAREA') {
|
||||
this.$target[0].dataset.visibilityComparator = 'equal';
|
||||
} else if (dependencyEl.type === 'file') {
|
||||
this.$target[0].dataset.visibilityComparator = 'fileSet';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,11 @@
|
||||
<we-button data-select-data-attribute='between'>Is between (included)</we-button>
|
||||
<we-button data-select-data-attribute='!between'>Is not between (excluded)</we-button>
|
||||
</we-select>
|
||||
<we-select data-name="hidden_condition_file_opt" data-attribute-name="visibilityComparator" data-no-preview="true">
|
||||
<!-- file comparator possibilities -->
|
||||
<we-button data-select-data-attribute="fileSet">Is set</we-button>
|
||||
<we-button data-select-data-attribute="!fileSet">Is not set</we-button>
|
||||
</we-select>
|
||||
</we-row>
|
||||
<we-select class="o_we_large" data-name="hidden_condition_no_text_opt" data-attribute-name="visibilityCondition" data-no-preview="true">
|
||||
<!-- checkbox, select, radio possible values -->
|
||||
|
||||
Reference in New Issue
Block a user