summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJason Van Malder <jvm@odoo.com>2020-01-30 08:16:33 +0000
committerJason Van Malder <jvm@odoo.com>2020-01-31 17:20:34 +0000
commitcf2f53e4cf4e8f5e2e2d23c5aaf4554630be68c8 (patch)
treea71673dfbb77e8b11737acd37ba02b9e6cf5e9a2 /addons
parent58732e4dc80234f9fdbf560101aac8a40ddd325c (diff)
[FIX] web_editor: fix required html fields
Issue - Studio - Add an required html field - Create new record - Leave it empty It is saved Cause The isSet function of FieldHtml widget, have a "/" in the <br> tag and summernote empty = <p><br></p>. If you add a space, the value becomes <p>&nbsp;&nbsp; <p>. Solution Remove the "/" and the spaces, check if value != <p></p> && <p><br></p> OPW-2183687 closes odoo/odoo#44427 X-original-commit: c984b1b1210cea1e63f3bc66cec2120554c76c2a Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/web_editor/static/src/js/backend/field_html.js3
-rw-r--r--addons/web_editor/static/tests/field_html_tests.js38
2 files changed, 40 insertions, 1 deletions
diff --git a/addons/web_editor/static/src/js/backend/field_html.js b/addons/web_editor/static/src/js/backend/field_html.js
index 0fe35887a7b..75548eee4b8 100644
--- a/addons/web_editor/static/src/js/backend/field_html.js
+++ b/addons/web_editor/static/src/js/backend/field_html.js
@@ -116,7 +116,8 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
* @override
*/
isSet: function () {
- return this.value && this.value !== "<p><br/></p>" && this.value.match(/\S/);
+ var value = this.value && this.value.split('&nbsp;').join('').replace(/\s/g, ''); // Removing spaces & html spaces
+ return value && value !== "<p></p>" && value !== "<p><br></p>" && value.match(/\S/);
},
/**
* @override
diff --git a/addons/web_editor/static/tests/field_html_tests.js b/addons/web_editor/static/tests/field_html_tests.js
index 6c4c3f9c5a3..ff50e0ef809 100644
--- a/addons/web_editor/static/tests/field_html_tests.js
+++ b/addons/web_editor/static/tests/field_html_tests.js
@@ -22,6 +22,11 @@ QUnit.module('web_editor', {}, function () {
string: "Displayed name",
type: "char"
},
+ header: {
+ string: "Header",
+ type: "html",
+ required: true,
+ },
body: {
string: "Message",
type: "html"
@@ -30,6 +35,7 @@ QUnit.module('web_editor', {}, function () {
records: [{
id: 1,
display_name: "first record",
+ header: "<p> &nbsp;&nbsp; <br> </p>",
body: "<p>toto toto toto</p><p>tata</p>",
}],
},
@@ -126,6 +132,38 @@ QUnit.module('web_editor', {}, function () {
form.destroy();
});
+ QUnit.test('check if required field is set', async function (assert) {
+ assert.expect(1);
+
+ var form = await testUtils.createView({
+ View: FormView,
+ model: 'note.note',
+ data: this.data,
+ arch: '<form>' +
+ '<field name="header" widget="html" style="height: 100px" />' +
+ '</form>',
+ res_id: 1,
+ });
+
+ testUtils.mock.intercept(form, 'call_service', function (ev) {
+ if (ev.data.service === 'notification') {
+ assert.deepEqual(ev.data.args[0], {
+ "className": undefined,
+ "message": "<ul><li>Header</li></ul>",
+ "sticky": undefined,
+ "title": "The following fields are invalid:",
+ "type": "danger"
+ });
+ }
+ }, true);
+
+ await testUtils.form.clickEdit(form);
+ await testUtils.nextTick();
+ await testUtils.dom.click(form.$('.o_form_button_save'));
+
+ form.destroy();
+ });
+
QUnit.test('colorpicker', async function (assert) {
assert.expect(6);