[FIX] web: fix email and phone widgets with empty value
When the value is empty in a related field, string of the element was displaying "false" instead of an empty string which is not what we expect. This commit fixes that issue. Task ID 2119333 PR #40949
This commit is contained in:
committed by
Thibault Delavallée
parent
1ec887b773
commit
75f7ab0608
@@ -79,7 +79,7 @@ Phone.include({
|
||||
*/
|
||||
_renderReadonly: function () {
|
||||
var def = this._super.apply(this, arguments);
|
||||
if (this.enableSMS) {
|
||||
if (this.enableSMS && this.value) {
|
||||
var $composerButton = $('<a>', {
|
||||
title: _t('Send SMS Text Message'),
|
||||
href: '',
|
||||
|
||||
@@ -18,6 +18,15 @@ QUnit.module('fields', {
|
||||
message: "",
|
||||
}]
|
||||
},
|
||||
visitor: {
|
||||
fields: {
|
||||
mobile: {string: "mobile", type: "text"},
|
||||
},
|
||||
records: [{
|
||||
id: 1,
|
||||
mobile: "+32494444444",
|
||||
}]
|
||||
},
|
||||
};
|
||||
}
|
||||
}, function () {
|
||||
@@ -32,6 +41,7 @@ QUnit.module('fields', {
|
||||
data: this.data,
|
||||
arch: '<form><sheet><field name="message" widget="sms_widget"/></sheet></form>',
|
||||
});
|
||||
|
||||
assert.containsOnce(form, '.o_sms_count', "Should have a sms counter");
|
||||
assert.strictEqual(form.$('.o_sms_count').text(), '0 characters, fits in 0 SMS (GSM7) ',
|
||||
'Should be "0 characters, fits in 0 SMS (GSM7) " by default');
|
||||
@@ -70,5 +80,39 @@ QUnit.module('fields', {
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Sms widgets with non-empty initial value', async function (assert) {
|
||||
assert.expect(1);
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'visitor',
|
||||
data: this.data,
|
||||
arch: `<form><sheet><field name="mobile" widget="sms_widget"/></sheet></form>`,
|
||||
res_id: 1,
|
||||
res_ids: [1],
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_text').text(), '+32494444444',
|
||||
'Should have the initial value');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Sms widgets with empty initial value', async function (assert) {
|
||||
assert.expect(1);
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: `<form><sheet><field name="message" widget="sms_widget"/></sheet></form>`,
|
||||
res_id: 1,
|
||||
res_ids: [1],
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_text').text(), '',
|
||||
'Should have the empty initial value');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1465,9 +1465,13 @@ var FieldEmail = InputField.extend({
|
||||
* @private
|
||||
*/
|
||||
_renderReadonly: function () {
|
||||
this.$el.text(this.value)
|
||||
.addClass('o_form_uri o_text_overflow')
|
||||
.attr('href', this.prefix + ':' + this.value);
|
||||
if (this.value) {
|
||||
this.$el.text(this.value)
|
||||
.addClass('o_form_uri o_text_overflow')
|
||||
.attr('href', this.prefix + ':' + this.value);
|
||||
} else {
|
||||
this.$el.text('');
|
||||
}
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -31,6 +31,7 @@ QUnit.module('basic_fields', {
|
||||
display_name: {string: "Displayed name", type: "char", searchable: true},
|
||||
foo: {string: "Foo", type: "char", default: "My little Foo Value", searchable: true, trim: true},
|
||||
bar: {string: "Bar", type: "boolean", default: true, searchable: true},
|
||||
empty_string: {string: "Empty string", type: "char", default: false, searchable: true, trim: true},
|
||||
txt: {string: "txt", type: "text", default: "My little txt Value\nHo-ho-hoooo Merry Christmas"},
|
||||
int_field: {string: "int_field", type: "integer", sortable: true, searchable: true},
|
||||
qux: {string: "Qux", type: "float", digits: [16,1], searchable: true},
|
||||
@@ -996,6 +997,30 @@ QUnit.module('basic_fields', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('email field with empty value', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<group>' +
|
||||
'<field name="empty_string" widget="email"/>' +
|
||||
'</group>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
var $mailtoLink = form.$('a.o_form_uri.o_field_widget.o_text_overflow');
|
||||
assert.strictEqual($mailtoLink.text(), '',
|
||||
"the value should be displayed properly");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
|
||||
QUnit.module('FieldChar');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user