diff --git a/web_widget_x2many_2d_matrix/README.rst b/web_widget_x2many_2d_matrix/README.rst index 6be504c4..5fb296be 100644 --- a/web_widget_x2many_2d_matrix/README.rst +++ b/web_widget_x2many_2d_matrix/README.rst @@ -49,8 +49,7 @@ show_column_totals Known issues / Roadmap ====================== -* no validation yet -* it would be better to instantiate the proper field widget and let it render the input +* it would be worth trying to instantiate the proper field widget and let it render the input Credits ======= diff --git a/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js b/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js index 191ffad6..0c818548 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js +++ b/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js @@ -209,6 +209,14 @@ openerp.web_widget_x2many_2d_matrix = function(instance) // validate a value validate_xy_value: function(val) { + try + { + this.parse_xy_value(val); + } + catch(e) + { + return false; + } return true; }, @@ -308,10 +316,12 @@ openerp.web_widget_x2many_2d_matrix = function(instance) val = $this.val() if(self.validate_xy_value(val)) { - data = {} - data[self.field_value] = self.parse_xy_value(val); - $this.siblings('span').text( - self.format_xy_value(self.parse_xy_value(val))); + var data = {}, value = self.parse_xy_value(val); + data[self.field_value] = value; + + $this.siblings('span').text(self.format_xy_value(value)); + $this.val(self.format_xy_value(value)); + self.dataset.write($this.data('id'), data); $this.parent().removeClass('oe_form_invalid'); self.compute_totals(); @@ -341,6 +351,11 @@ openerp.web_widget_x2many_2d_matrix = function(instance) this.$el.find('input').first().focus(); }, + is_syntax_valid: function() + { + return this.$el.find('.oe_form_invalid').length == 0; + }, + // deactivate view related functions load_views: function() {}, reload_current_view: function() {},