Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/191834

Change subject: Unbreak form submission in JavaScript
......................................................................

Unbreak form submission in JavaScript

We hook way too many events on everything.

FormLayout:
  There was no way to actually submit the form, as the 'submit'
  event's default action was always prevented.

ButtonInputWidget:
  There was no way to actually submit any form with the button, as the
  'click' event's default action was always prevented (in
  ButtonElement).

Change-Id: Ie84826c7cfd4519d132b6b5206ad67c76f8b3eef
---
M src/layouts/FormLayout.js
M src/widgets/ButtonInputWidget.js
2 files changed, 19 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/34/191834/1

diff --git a/src/layouts/FormLayout.js b/src/layouts/FormLayout.js
index 8c0d151..22bb066 100644
--- a/src/layouts/FormLayout.js
+++ b/src/layouts/FormLayout.js
@@ -46,7 +46,11 @@
 /* Events */
 
 /**
+ * The HTML form was submitted. If the submission is handled, call 
`e.preventDefault()` to prevent
+ * HTML form submission.
+ *
  * @event submit
+ * @param {jQuery.Event} e Submit event
  */
 
 /* Static Properties */
@@ -61,7 +65,6 @@
  * @param {jQuery.Event} e Submit event
  * @fires submit
  */
-OO.ui.FormLayout.prototype.onFormSubmit = function () {
-       this.emit( 'submit' );
-       return false;
+OO.ui.FormLayout.prototype.onFormSubmit = function ( e ) {
+       this.emit( 'submit', e );
 };
diff --git a/src/widgets/ButtonInputWidget.js b/src/widgets/ButtonInputWidget.js
index 9777699..8f9c813 100644
--- a/src/widgets/ButtonInputWidget.js
+++ b/src/widgets/ButtonInputWidget.js
@@ -39,6 +39,7 @@
 
        // Properties (must be set before parent constructor, which calls 
#setValue)
        this.useInputTag = config.useInputTag;
+       this.type = config.type;
 
        // Parent constructor
        OO.ui.ButtonInputWidget.super.call( this, config );
@@ -121,3 +122,15 @@
        }
        return this;
 };
+
+/**
+ * @inheritdoc
+ */
+OO.ui.ButtonInputWidget.prototype.onClick = function ( e ) {
+       var ret = OO.ui.ButtonElement.prototype.onClick.call( this, e );
+       if ( this.type === 'submit' ) {
+               // Never prevent default action (form submission)
+               return true;
+       }
+       return ret;
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/191834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie84826c7cfd4519d132b6b5206ad67c76f8b3eef
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to