diff --git a/src/common.js b/src/common.js index d9433d4e16..619cda8a87 100644 --- a/src/common.js +++ b/src/common.js @@ -581,7 +581,8 @@ init: function(attributes) { this.attributes = attributes; this.el = jQuery('', { - 'class': 'btn btn-default' + 'class': 'btn btn-default', + 'type': 'button' }).text(attributes.string || '') .append(jQuery('', { 'class': 'glyphicon', diff --git a/src/window.js b/src/window.js index 7adb579909..aa13e8af5b 100644 --- a/src/window.js +++ b/src/window.js @@ -39,7 +39,7 @@ 'class': 'modal fade', role: 'dialog' }); - var content = jQuery('
', { + var content = jQuery('', { 'class': 'modal-content' }).appendTo(jQuery('', { 'class': 'modal-dialog modal-lg' @@ -61,7 +61,8 @@ if (view_type == 'form') { footer.append(jQuery('', { - 'class': 'btn btn-link' + 'class': 'btn btn-link', + 'type': 'button' }).append(!kwargs.new_ && this.screen.current_record.id < 0 ? 'Delete' : 'Cancel') .click(function() { @@ -71,7 +72,8 @@ if (kwargs.new_ && this.many) { footer.append(jQuery('', { - 'class': 'btn btn-default' + 'class': 'btn btn-default', + 'type': 'button' }).append('New').click(function() { this.response('RESPONSE_ACCEPT'); }.bind(this))); @@ -79,17 +81,19 @@ if (this.save_current) { footer.append(jQuery('', { - 'class': 'btn btn-primary' - }).append('Save').click(function() { - this.response('RESPONSE_OK'); - }.bind(this))); + 'class': 'btn btn-primary', + 'type': 'submit' + }).append('Save')); } else { footer.append(jQuery('', { - 'class': 'btn btn-primary' - }).append('OK').click(function() { - this.response('RESPONSE_OK'); - }.bind(this))); + 'class': 'btn btn-primary', + 'type': 'submit' + }).append('OK')); } + content.submit(function(e) { + this.response('RESPONSE_OK'); + e.preventDefault(); + }.bind(this)); if (view_type == 'tree') { var menu = jQuery('').appendTo(body); @@ -461,7 +465,7 @@ 'class': 'modal fade', role: 'dialog' }); - var content = jQuery('', { + var content = jQuery('', { 'class': 'modal-content' }).appendTo(jQuery('', { 'class': 'modal-dialog modal-lg' @@ -479,15 +483,19 @@ }).appendTo(content); jQuery('', { - 'class': 'btn btn-link' + 'class': 'btn btn-link', + 'type': 'button' }).append('Cancel').click(function() { this.response('RESPONSE_CANCEL'); }.bind(this)).appendTo(footer); jQuery('', { - 'class': 'btn btn-primary' - }).append('OK').click(function() { + 'class': 'btn btn-primary', + 'type': 'submit' + }).append('OK').appendTo(footer); + content.submit(function(e) { this.response('RESPONSE_OK'); - }.bind(this)).appendTo(footer); + e.preventDefault(); + }.bind(this)); this.screen = new Sao.Screen('res.user', { mode: [] @@ -559,7 +567,7 @@ 'class': 'modal fade', role: 'dialog' }); - var content = jQuery('', { + var content = jQuery('', { 'class': 'modal-content' }).appendTo(jQuery('', { 'class': 'modal-dialog modal-lg' @@ -577,15 +585,19 @@ }).appendTo(content); jQuery('', { - 'class': 'btn btn-link' + 'class': 'btn btn-link', + 'type': 'button' }).append('Cancel').click(function() { this.response('RESPONSE_CANCEL'); }.bind(this)).appendTo(footer); jQuery('', { - 'class': 'btn btn-primary' - }).append('OK').click(function() { + 'class': 'btn btn-primary', + 'type': 'submit' + }).append('OK').appendTo(footer); + content.submit(function(e) { this.response('RESPONSE_OK'); - }.bind(this)).appendTo(footer); + e.preventDefault(); + }.bind(this)); var group = jQuery('', { 'class': 'form-group' diff --git a/src/wizard.js b/src/wizard.js index ee701702e3..cecd64c835 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -173,7 +173,7 @@ 'class': 'wizard-dialog modal fade', role: 'dialog' }); - var content = jQuery('', { + var content = this.content = jQuery('', { 'class': 'modal-content' }).appendTo(jQuery('', { 'class': 'modal-dialog modal-lg' @@ -200,12 +200,22 @@ var button = Sao.Wizard.Dialog._super._get_button.call(this, definition); this.footer.append(button.el); - button.el.click(function() { - this.response(definition.state); - }.bind(this)); + if (definition['default']) { + this.content.unbind('submit'); + this.content.submit(function(e) { + this.response(definition.state); + e.preventDefault(); + }.bind(this)); + button.el.attr('type', 'submit'); + } else { + button.el.click(function() { + this.response(definition.state); + }.bind(this)); + } return button; }, update: function(view, defaults, buttons) { + this.content.unbind('submit'); Sao.Wizard.Dialog._super.update.call(this, view, defaults, buttons); this.dialog.modal('show');