Skip to content

Commit

Permalink
[FIX] website: fix conditional visibility based on file upload
Browse files Browse the repository at this point in the history
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#93756

X-original-commit: fec02f6
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Antoine Dupuis (andu) <andu@odoo.com>
  • Loading branch information
antoine162 committed Jun 16, 2022
1 parent 21a1d13 commit 0c50be8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addons/website/static/src/snippets/s_website_form/000.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(':')) {
Expand Down
4 changes: 4 additions & 0 deletions addons/website/static/src/snippets/s_website_form/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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';
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions addons/website/views/snippets/s_website_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down

0 comments on commit 0c50be8

Please sign in to comment.