[FIX] web: do not display falsy url field widgets

Before this fix, unset char fields with the url widget in form view
displayed "false", whereas they should simply be empty. This is a
side-effect of commit [1], which aims at reducing the shift between
readonly and edit modes in form views.

[1] https://github.com/odoo/odoo/commit/288b24cbdf54ac0dbee7e012f074fac9a0c68238

closes odoo/odoo#68330

X-original-commit: de1f7ab77d37adbbc68e640ea9877721bfc869d2
Signed-off-by: Michaël Mattiello <mcm-odoo@users.noreply.github.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2021-03-25 11:03:54 +00:00
parent 2f6dd3d172
commit 2c69b323b1
2 changed files with 26 additions and 0 deletions
@@ -1695,6 +1695,9 @@ var UrlWidget = InputField.extend({
* @private
*/
_renderReadonly: function () {
if (!this.value) {
return;
}
let href = this.value;
if (this.value && !this.websitePath) {
const regex = /^(?:[fF]|[hH][tT])[tT][pP][sS]?:\/\//;
@@ -2100,6 +2100,29 @@ QUnit.module('basic_fields', {
list.destroy();
});
QUnit.test('url widget with falsy value', async function (assert) {
assert.expect(4);
this.data.partner.records[0].foo = false;
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="foo" widget="url"/></form>',
res_id: 1,
});
assert.containsOnce(form, 'div.o_field_widget[name=foo]');
assert.strictEqual(form.$('.o_field_widget[name=foo]').text(), "");
await testUtils.form.clickEdit(form);
assert.containsOnce(form, 'input.o_field_widget[name=foo]');
assert.strictEqual(form.$('.o_field_widget[name=foo]').val(), "");
form.destroy();
});
QUnit.module('CopyClipboard');
QUnit.test('Char & Text Fields: Copy to clipboard button', async function (assert) {