Set default type attribute for button html elements
authorStephan Gambke <s7eph4n@gmail.com>
Tue, 30 Oct 2012 19:06:16 +0000 (20:06 +0100)
committerStephan Gambke <s7eph4n@gmail.com>
Tue, 30 Oct 2012 20:45:17 +0000 (21:45 +0100)
According to standard the default type for <button> elements is "submit". Depending on compatibility mode IE might use "button", instead.
To work around the IE bug this patch forces the standard "submit", if nothing is specified explicitly.

See remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx :
-----
The default value of the type attribute depends on the current document compatibility mode. The default value is submit. In other compatibility modes the default value is button.
...
Windows Internet Explorer 8 and later. The default value of the type attribute depends on the current document compatibility mode. In IE8 Standards mode, the default value is submit.
In other compatibility modes and earlier versions of Windows Internet Explorer, the default value is button.
-----

Change-Id: I3b97a8cac74bbfca63699dfcbf1cc5e9a2cef193

includes/Html.php
tests/phpunit/includes/HtmlTest.php

index 5be67ab..71cd0b9 100644 (file)
@@ -234,6 +234,13 @@ class Html {
                        unset( $attribs['maxlength'] );
                }
 
+               // According to standard the default type for <button> elements is "submit".
+               // Depending on compatibility mode IE might use "button", instead.
+               // We enforce the standard "submit".
+               if ( $element == 'button' && !isset( $attribs['type'] ) ) {
+                       $attribs['type'] = 'submit';
+               }
+
                return "<$element" . self::expandAttributes(
                        self::dropDefaults( $element, $attribs ) ) . '>';
        }
@@ -301,7 +308,6 @@ class Html {
                        'button' => array(
                                'formaction' => 'GET',
                                'formenctype' => 'application/x-www-form-urlencoded',
-                               'type' => 'submit',
                        ),
                        'canvas' => array(
                                'height' => '150',
index 95a6cb0..65dd924 100644 (file)
@@ -73,7 +73,7 @@ class HtmlTest extends MediaWikiTestCase {
        }
 
        public function testExpandAttributesSkipsNullAndFalse() {
-               
+
                ### EMPTY ########
                $this->assertEmpty(
                        Html::expandAttributes( array( 'foo' => null ) ),
@@ -442,7 +442,7 @@ class HtmlTest extends MediaWikiTestCase {
        }
 
        /**
-        * Test out Html::element drops default value
+        * Test out Html::element drops or enforces default value
         * @cover Html::dropDefaults
         * @dataProvider provideElementsWithAttributesHavingDefaultValues
         */
@@ -461,15 +461,12 @@ class HtmlTest extends MediaWikiTestCase {
                        'area', array( 'shape' => 'rect' )
                );
 
-               $cases[] = array( '<button></button>',
+               $cases[] = array( '<button type=submit></button>',
                        'button', array( 'formaction' => 'GET' )
                );
-               $cases[] = array( '<button></button>',
+               $cases[] = array( '<button type=submit></button>',
                        'button', array( 'formenctype' => 'application/x-www-form-urlencoded' )
                );
-               $cases[] = array( '<button></button>',
-                       'button', array( 'type' => 'submit' )
-               );
 
                $cases[] = array( '<canvas></canvas>',
                        'canvas', array( 'height' => '150' )
@@ -560,6 +557,13 @@ class HtmlTest extends MediaWikiTestCase {
                        'input', array( 'type' => 'range', 'value' => '' ),
                );
 
+               # <button> specific handling
+               # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
+               $cases[] = array( '<button type=submit></button>',
+                       'button', array( 'type' => 'submit' ),
+                       'According to standard the default type is "submit". Depending on compatibility mode IE might use "button", instead.',
+               );
+
                # <select> specifc handling
                $cases[] = array( '<select multiple></select>',
                        'select', array( 'size' => '4', 'multiple' => true ),