[IMP] web: FieldInteger and FieldFloat can use input of type number

This allow the browser/device to handle the experience of handling number in a more native way.

FieldInteger and FieldFloat now inherits from NumericField because we want
to format it or not dependent of the view (readonly or edit) and the
NumericField will manage it.

We do that because input type number can't take a value with comma on Chrome
(FireFox is more permissive but not perfect because comma is the separator
for decimal in this case).

Task #1880376
This commit is contained in:
svs-odoo
2018-09-07 16:18:45 +02:00
committed by Géry Debongnie
parent 16aeecc73d
commit 74fcd3ac3b
3 changed files with 227 additions and 30 deletions
@@ -707,6 +707,71 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('float field with type number option', function (assert) {
assert.expect(4);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="qux" options="{\'type\': \'number\'}"/>' +
'</form>',
res_id: 4,
translateParameters: {
thousands_sep: ",",
grouping: [3, 0],
},
});
form.$buttons.find('.o_form_button_edit').click();
assert.ok(form.$('.o_field_widget')[0].hasAttribute('type'),
'Float field with option type must have a type attribute.');
assert.strictEqual(form.$('.o_field_widget').attr('type'), 'number',
'Float field with option type must have a type attribute equals to "number".');
form.$('input').val('123456.7890').trigger('input');
form.$buttons.find('.o_form_button_save').click();
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_widget').val(), '123456.789',
'Float value must be not formatted if input type is number.');
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('.o_field_widget').text(), '123,456.8',
'Float value must be formatted in readonly view even if the input type is number.');
form.destroy();
});
QUnit.test('float field without type number option', function (assert) {
assert.expect(2);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="qux"/>' +
'</form>',
res_id: 4,
translateParameters: {
thousands_sep: ",",
grouping: [3, 0],
},
});
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_widget').attr('type'), 'text',
'Float field with option type must have a text type (default type).');
form.$('input').val('123456.7890').trigger('input');
form.$buttons.find('.o_form_button_save').click();
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_widget').val(), '123,456.8',
'Float value must be formatted if input type isn\'t number.');
form.destroy();
});
QUnit.module('FieldEmail');
QUnit.test('email field in form view', function (assert) {
@@ -3359,6 +3424,72 @@ QUnit.module('basic_fields', {
list.destroy();
});
QUnit.test('integer field with type number option', function (assert) {
assert.expect(4);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="int_field" options="{\'type\': \'number\'}"/>' +
'</form>',
res_id: 4,
translateParameters: {
thousands_sep: ",",
grouping: [3, 0],
},
});
form.$buttons.find('.o_form_button_edit').click();
assert.ok(form.$('.o_field_widget')[0].hasAttribute('type'),
'Integer field with option type must have a type attribute.');
assert.strictEqual(form.$('.o_field_widget').attr('type'), 'number',
'Integer field with option type must have a type attribute equals to "number".');
form.$('input').val('1234567890').trigger('input');
form.$buttons.find('.o_form_button_save').click();
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_widget').val(), '1234567890',
'Integer value must be not formatted if input type is number.');
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('.o_field_widget').text(), '1,234,567,890',
'Integer value must be formatted in readonly view even if the input type is number.');
form.destroy();
});
QUnit.test('integer field without type number option', function (assert) {
assert.expect(2);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="int_field"/>' +
'</form>',
res_id: 4,
translateParameters: {
thousands_sep: ",",
grouping: [3, 0],
},
});
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_widget').attr('type'), 'text',
'Integer field without option type must have a text type (default type).');
form.$('input').val('1234567890').trigger('input');
form.$buttons.find('.o_form_button_save').click();
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_field_widget').val(), '1,234,567,890',
'Integer value must be formatted if input type isn\'t number.');
form.destroy();
});
QUnit.module('FieldFloatTime');
QUnit.test('float_time field in form view', function (assert) {