Do not fail to set value of the wrong type to Dict Entry widget
Closes #13621
This commit is contained in:
+10
-3
@@ -5406,7 +5406,7 @@ function eval_pyson(value){
|
||||
this.input.prop('disabled', readonly);
|
||||
},
|
||||
set_value: function(value) {
|
||||
this.input.prop('checked', value);
|
||||
this.input.prop('checked', Boolean(value));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5522,7 +5522,8 @@ function eval_pyson(value){
|
||||
return value;
|
||||
},
|
||||
set_value: function(value, options) {
|
||||
if (value !== null) {
|
||||
if ((typeof(value) == 'number') ||
|
||||
(value instanceof Sao.Decimal)) {
|
||||
this.input.val(value);
|
||||
this.input_text.val(value.toLocaleString(
|
||||
Sao.i18n.BC47(Sao.i18n.getlang()), options));
|
||||
@@ -5658,7 +5659,13 @@ function eval_pyson(value){
|
||||
return this._parse(this.format, this.input.val());
|
||||
},
|
||||
set_value: function(value) {
|
||||
this.input.val(this._format(this.format, value));
|
||||
if ((value instanceof Sao.DateTime) ||
|
||||
(value instanceof Sao.Date)) {
|
||||
value = this._format(this.format, value);
|
||||
} else {
|
||||
value = '';
|
||||
}
|
||||
this.input.val(value);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of this
|
||||
# repository contains the full copyright notices and license terms.
|
||||
|
||||
import datetime as dt
|
||||
import decimal
|
||||
import gettext
|
||||
import locale
|
||||
@@ -64,7 +65,7 @@ class DictEntry(object):
|
||||
return self.widget.get_text()
|
||||
|
||||
def set_value(self, value):
|
||||
self.widget.set_text(value or '')
|
||||
self.widget.set_text(str(value or ''))
|
||||
reset_position(self.widget)
|
||||
|
||||
def set_readonly(self, readonly):
|
||||
@@ -286,7 +287,7 @@ class DictIntegerEntry(DictEntry):
|
||||
return None
|
||||
|
||||
def set_value(self, value):
|
||||
if value is not None:
|
||||
if isinstance(value, (int, float, Decimal)):
|
||||
txt_val = locale.format_string('%d', value, True)
|
||||
else:
|
||||
txt_val = ''
|
||||
@@ -323,7 +324,7 @@ class DictFloatEntry(DictIntegerEntry):
|
||||
else:
|
||||
self.widget.digits = None
|
||||
self.widget.set_width_chars(self.width)
|
||||
if value is not None:
|
||||
if isinstance(value, (int, float, Decimal)):
|
||||
txt_val = locale.localize(
|
||||
'{0:.{1}f}'.format(value, digits[1]), True)
|
||||
else:
|
||||
@@ -369,7 +370,8 @@ class DictDateTimeEntry(DictEntry):
|
||||
return untimezoned_date(self.widget.props.value)
|
||||
|
||||
def set_value(self, value):
|
||||
self.widget.props.value = timezoned_date(value)
|
||||
self.widget.props.value = (
|
||||
timezoned_date(value) if isinstance(value, dt.datetime) else None)
|
||||
|
||||
def set_readonly(self, readonly):
|
||||
for child in self.widget.get_children():
|
||||
@@ -404,7 +406,7 @@ class DictDateEntry(DictEntry):
|
||||
return self.widget.props.value
|
||||
|
||||
def set_value(self, value):
|
||||
self.widget.props.value = value
|
||||
self.widget.props.value = value if isinstance(value, dt.date) else None
|
||||
|
||||
def set_readonly(self, readonly):
|
||||
super().set_readonly(readonly)
|
||||
|
||||
Reference in New Issue
Block a user