[IMP] web: trim FieldEmail widget value

before this commit, email widget was not trimming value and due to which
space aroung email value remain as it is added by user.

after this commit, email widget will trim the value and remove leading/trailing
space.

task-2197432

closes odoo/odoo#47470

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mohammed Shekha
2020-03-24 08:02:13 +00:00
committed by Aaron Bohy
parent efd5401ee1
commit 5353fb2496
2 changed files with 37 additions and 0 deletions
@@ -1506,6 +1506,20 @@ var FieldEmail = InputField.extend({
this.$el.text('');
}
},
/**
* Trim the value input by the user.
*
* @override
* @private
* @param {any} value
* @param {Object} [options]
*/
_setValue: function (value, options) {
if (this.field.trim) {
value = value.trim();
}
return this._super(value, options);
},
//--------------------------------------------------------------------------
// Handlers
@@ -1065,6 +1065,29 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('email field trim user value', async function (assert) {
assert.expect(1);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="foo" widget="email"/></form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
await testUtils.fields.editInput(form.$('input[name="foo"]'), ' abc@abc.com ');
await testUtils.form.clickSave(form);
await testUtils.form.clickEdit(form);
assert.strictEqual(form.$('input[name="foo"]').val(), 'abc@abc.com',
"Foo value should have been trimmed");
form.destroy();
});
QUnit.module('FieldChar');