jenkins-bot has submitted this change and it was merged.

Change subject: Text input widget enter event
......................................................................


Text input widget enter event

Objective:

* Add an event to single line text input widgets to detect when the enter
  key has been pressed

Changes:

ve.ui.TextInputWidget.js
* Retain value of multiline config option
* Add key press handler to detect pressing of enter key
* Emit 'enter' event when enter key is pressed if input is single line

Bonus:

* Add missing documentation for multiline config option

Change-Id: Id9c64343f4a2ea8f0f45213fd2b59ca87c805b24
---
M modules/ve/ui/widgets/ve.ui.TextInputWidget.js
1 file changed, 27 insertions(+), 0 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/ui/widgets/ve.ui.TextInputWidget.js 
b/modules/ve/ui/widgets/ve.ui.TextInputWidget.js
index 904ede3..faef38c 100644
--- a/modules/ve/ui/widgets/ve.ui.TextInputWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.TextInputWidget.js
@@ -15,6 +15,7 @@
  * @param {Object} [config] Config options
  * @cfg {string} [placeholder] Placeholder text
  * @cfg {string} [icon] Symbolic name of icon
+ * @cfg {boolean} [multiline=false] Allow multiple lines of text
  */
 ve.ui.TextInputWidget = function VeUiTextInputWidget( config ) {
        // Parent constructor
@@ -22,6 +23,10 @@
 
        // Properties
        this.pending = 0;
+       this.multiline = !!config.multiline;
+
+       // Events
+       this.$input.on( 'keypress', ve.bind( this.onKeyPress, this ) );
 
        // Initialization
        this.$.addClass( 've-ui-textInputWidget' );
@@ -45,9 +50,31 @@
 
 ve.inheritClass( ve.ui.TextInputWidget, ve.ui.InputWidget );
 
+/* Events */
+
+/**
+ * User presses enter inside the text box.
+ *
+ * Not called if input is multiline.
+ *
+ * @event enter
+ */
+
 /* Methods */
 
 /**
+ * Handles key press events.
+ *
+ * @param {jQuery.Event} e Key press event
+ * @emits enter If enter key is pressed and input is not multiline
+ */
+ve.ui.TextInputWidget.prototype.onKeyPress = function ( e ) {
+       if ( e.which === ve.Keys.ENTER && !this.multiline ) {
+               this.emit( 'enter' );
+       }
+};
+
+/**
  * Get input element.
  *
  * @method

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id9c64343f4a2ea8f0f45213fd2b59ca87c805b24
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to