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

Change subject: Document and enforce allowed types for ButtonInputWidget and 
TextInputWidget
......................................................................


Document and enforce allowed types for ButtonInputWidget and TextInputWidget

Seriously people, please don't do `new TextInputWidget( { type: 'hidden' } )`, 
okay?

For TextInputWidget we only allow the types that are still obviously
strings. Notably, 'number', 'color', and the multitude of
date-and-time-related types are not allowed. If you're feeling lucky,
set them on the <input/> manually with jQuery or whatever.

Change-Id: If7f0610d0ec9e8a27c0fb4534b0ab029ca2d06c3
---
M bin/testsuitegenerator.rb
M php/widgets/ButtonInputWidget.php
M php/widgets/TextInputWidget.php
M src/widgets/ButtonInputWidget.js
M src/widgets/TextInputWidget.js
5 files changed, 22 insertions(+), 9 deletions(-)

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



diff --git a/bin/testsuitegenerator.rb b/bin/testsuitegenerator.rb
index 28ab1a8..ce3a757 100644
--- a/bin/testsuitegenerator.rb
+++ b/bin/testsuitegenerator.rb
@@ -31,8 +31,8 @@
        # values to test for names
        sensible_values = {
                'href' => ['http://example.com/'],
-               ['TextInputWidget', 'type'] => %w[text password],
-               ['ButtonInputWidget', 'type'] => %w[button input],
+               ['TextInputWidget', 'type'] => %w[text password foo],
+               ['ButtonInputWidget', 'type'] => %w[button submit foo],
                ['FieldLayout', 'help'] => true, # different PHP and JS 
implementations
                ['FieldsetLayout', 'help'] => true, # different PHP and JS 
implementations
                'type' => %w[text button],
diff --git a/php/widgets/ButtonInputWidget.php 
b/php/widgets/ButtonInputWidget.php
index b3bcb63..0db90a0 100644
--- a/php/widgets/ButtonInputWidget.php
+++ b/php/widgets/ButtonInputWidget.php
@@ -60,8 +60,11 @@
        }
 
        protected function getInputElement( $config ) {
+               $type = in_array( $config['type'], array( 'button', 'submit', 
'reset' ) ) ?
+                       $config['type'] :
+                       'button';
                $input = new Tag( $config['useInputTag'] ? 'input' : 'button' );
-               $input->setAttributes( array( 'type' => $config['type'] ) );
+               $input->setAttributes( array( 'type' => $type ) );
                return $input;
        }
 
diff --git a/php/widgets/TextInputWidget.php b/php/widgets/TextInputWidget.php
index a5f31f7..e930790 100644
--- a/php/widgets/TextInputWidget.php
+++ b/php/widgets/TextInputWidget.php
@@ -25,7 +25,8 @@
 
        /**
         * @param array $config Configuration options
-        * @param string $config['type'] HTML tag `type` attribute (default: 
'text')
+        * @param string $config['type'] HTML tag `type` attribute: 'text', 
'password', 'search', 'email'
+        *   or 'url'. Ignored if `multiline` is true. (default: 'text')
         * @param string $config['placeholder'] Placeholder text
         * @param boolean $config['autofocus'] Ask the browser to focus this 
widget, using the 'autofocus'
         *   HTML attribute (default: false)
@@ -37,6 +38,7 @@
        public function __construct( array $config = array() ) {
                // Config initialization
                $config = array_merge( array(
+                       'type' => 'text',
                        'readOnly' => false,
                        'autofocus' => false,
                        'required' => false,
@@ -101,7 +103,9 @@
                if ( isset( $config['multiline'] ) && $config['multiline'] ) {
                        return new Tag( 'textarea' );
                } else {
-                       $type = isset( $config['type'] ) ? $config['type'] : 
'text';
+                       $type = in_array( $config['type'], array( 'text', 
'password', 'search', 'email', 'url' ) ) ?
+                               $config['type'] :
+                               'text';
                        $input = new Tag( 'input' );
                        $input->setAttributes( array( 'type' => $type ) );
                        return $input;
diff --git a/src/widgets/ButtonInputWidget.js b/src/widgets/ButtonInputWidget.js
index 1d4d97f..31f8424 100644
--- a/src/widgets/ButtonInputWidget.js
+++ b/src/widgets/ButtonInputWidget.js
@@ -72,8 +72,10 @@
  * @private
  */
 OO.ui.ButtonInputWidget.prototype.getInputElement = function ( config ) {
-       var html = '<' + ( config.useInputTag ? 'input' : 'button' ) + ' 
type="' + config.type + '">';
-       return $( html );
+       var type = [ 'button', 'submit', 'reset' ].indexOf( config.type ) !== 
-1 ?
+               config.type :
+               'button';
+       return $( '<' + ( config.useInputTag ? 'input' : 'button' ) + ' type="' 
+ type + '">' );
 };
 
 /**
diff --git a/src/widgets/TextInputWidget.js b/src/widgets/TextInputWidget.js
index 1ba2664..e71b4ad 100644
--- a/src/widgets/TextInputWidget.js
+++ b/src/widgets/TextInputWidget.js
@@ -26,7 +26,8 @@
  *
  * @constructor
  * @param {Object} [config] Configuration options
- * @cfg {string} [type='text'] The value of the HTML `type` attribute
+ * @cfg {string} [type='text'] The value of the HTML `type` attribute: 'text', 
'password', 'search',
+ *  'email' or 'url'. Ignored if `multiline` is true.
  * @cfg {string} [placeholder] Placeholder text
  * @cfg {boolean} [autofocus=false] Use an HTML `autofocus` attribute to
  *  instruct the browser to focus this widget.
@@ -367,7 +368,10 @@
  * @private
  */
 OO.ui.TextInputWidget.prototype.getInputElement = function ( config ) {
-       return config.multiline ? $( '<textarea>' ) : $( '<input type="' + 
config.type + '" />' );
+       var type = [ 'text', 'password', 'search', 'email', 'url' ].indexOf( 
config.type ) !== -1 ?
+               config.type :
+               'text';
+       return config.multiline ? $( '<textarea>' ) : $( '<input type="' + type 
+ '" />' );
 };
 
 /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If7f0610d0ec9e8a27c0fb4534b0ab029ca2d06c3
Gerrit-PatchSet: 2
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz DziewoƄski <matma....@gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisa...@openmailbox.org>
Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to