[FIX] web: Error on invalid date format on date field input
Steps to reproduce the bug: - Go to any field Date - Enter wrong date Bug: A traceback was raised. Now a warning is raised and the wrong value is removed. opw:1974747 closes odoo/odoo#33362 Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
@@ -13,6 +13,7 @@ var DateWidget = Widget.extend({
|
||||
type_of_date: "date",
|
||||
events: {
|
||||
'change.datetimepicker': 'changeDatetime',
|
||||
'error.datetimepicker': 'errorDatetime',
|
||||
'change .o_datepicker_input': 'changeDatetime',
|
||||
'input input': '_onInput',
|
||||
'keydown': '_onKeydown',
|
||||
@@ -103,6 +104,15 @@ var DateWidget = Widget.extend({
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Library clears the wrong date format so just ignore error
|
||||
*/
|
||||
errorDatetime: function (e) {
|
||||
if (!e.date.isValid()){
|
||||
this.do_warn(_t("Error"), e.date.toString());
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* Focuses the datepicker input. This function must be called in order to
|
||||
* prevent 'input' events triggered by the lib to bubble up, and to cause
|
||||
|
||||
@@ -2667,6 +2667,25 @@ QUnit.module('basic_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('date field should remove the date if the date is not valid', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners"><field name="date"/></form>',
|
||||
res_id: 4,
|
||||
});
|
||||
// switch to edit mode
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
// set an invalid date
|
||||
var $input = form.$('.o_field_widget[name=date] input');
|
||||
$input.val('mmmh').trigger('change');
|
||||
assert.strictEqual($input.text(), "", "The date field should be empty");
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('date field value should not set on first click', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user