[FIX] web_editor: hide toolbar for fields with no HTML support
Before this commit, only the immediate parent of a selected node was checked for HTML content support in order to determine the toolbar's visibility. This led to incorrectly displaying the toolbar for fields like the 'list-price' on an e-commerce product page, whose text content is wrapped in an extra 'span' element inside the field's span element. This commit fixes it by checking all of the node's ancestors up to the editable root for the attributes that determine if a field supports HTML content. This commit also prevents a server error if the user somehow styles the product's price (with ctrl+B for example. It's worth noting that such style would not be kept in the saved version of the page). lxml.HtmlElement's `text` property has `None` value if the span element does not contain any text before its first child element (see https://lxml.de/apidoc/lxml.html.html). Therefore an element like `<span><strong>42.00</strong></span>` would result in `None` when reading its `text` property. The `text_content` method is more suitable for such task as it returns the text content of an element and its children. task-3188550 opw-3171669 closes odoo/odoo#114867 X-original-commit: 524ba7f89286aa03ed6a4da30177c9ce7018c59a Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -518,7 +518,7 @@ class Monetary(models.AbstractModel):
|
||||
def from_html(self, model, field, element):
|
||||
lang = self.user_lang()
|
||||
|
||||
value = element.find('span').text.strip()
|
||||
value = element.find('span').text_content().strip()
|
||||
|
||||
return float(value.replace(lang.thousands_sep, '')
|
||||
.replace(lang.decimal_point, '.'))
|
||||
|
||||
@@ -13,6 +13,7 @@ const SmoothScrollOnDrag = require('web/static/src/js/core/smooth_scroll_on_drag
|
||||
const {getCSSVariableValue} = require('web_editor.utils');
|
||||
const gridUtils = require('@web_editor/js/common/grid_layout_utils');
|
||||
const QWeb = core.qweb;
|
||||
const {closestElement} = require('@web_editor/js/editor/odoo-editor/src/utils/utils');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -4189,8 +4190,8 @@ var SnippetsMenu = Widget.extend({
|
||||
}
|
||||
if (!range ||
|
||||
!$currentSelectionTarget.parents('#wrapwrap, .iframe-editor-wrapper .o_editable').length ||
|
||||
$(selection.anchorNode).parent('[data-oe-model]:not([data-oe-type="html"]):not([data-oe-field="arch"]):not([data-oe-translation-initial-sha])').length ||
|
||||
$(selection.focusNode).parent('[data-oe-model]:not([data-oe-type="html"]):not([data-oe-field="arch"]):not([data-oe-translation-initial-sha])').length ||
|
||||
closestElement(selection.anchorNode, '[data-oe-model]:not([data-oe-type="html"]):not([data-oe-field="arch"]):not([data-oe-translation-initial-sha])') ||
|
||||
closestElement(selection.focusNode, '[data-oe-model]:not([data-oe-type="html"]):not([data-oe-field="arch"]):not([data-oe-translation-initial-sha])') ||
|
||||
(e && $(e.target).closest('.fa, img').length ||
|
||||
this.options.wysiwyg.lastMediaClicked && $(this.options.wysiwyg.lastMediaClicked).is('.fa, img')) ||
|
||||
(this.options.wysiwyg.lastElement && !this.options.wysiwyg.lastElement.isContentEditable)
|
||||
|
||||
Reference in New Issue
Block a user