Do not fail to set value of the wrong type to Dict Entry widget
Closes #13621 (grafted from 380efdfcf2f12fd82a23a883eb9941d238f4f714) --HG-- branch : 7.0
This commit is contained in:
1 parent
a0e88c3d67
commit
dd03a5c068
2 files changed
+17
-8
No files matched your search
+10
-3
@@ -5133,7 +5133,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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5236,7 +5236,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));
|
||||
@@ -5369,7 +5370,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):
|
||||
@@ -279,7 +280,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 = ''
|
||||
@@ -316,7 +317,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:
|
||||
@@ -362,7 +363,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():
|
||||
@@ -397,7 +399,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