'input' => array(
'formaction' => 'GET',
'type' => 'text',
- 'value' => '',
),
'keygen' => array( 'keytype' => 'rsa' ),
'link' => array( 'media' => 'all' ),
&& strval( $attribs['type'] ) == 'text/css' ) {
unset( $attribs['type'] );
}
+ if ( $element === 'input' ) {
+ $type = isset( $attribs['type'] ) ? $attribs['type'] : null;
+ $value = isset( $attribs['value'] ) ? $attribs['value'] : null;
+ if ( $type === 'checkbox' || $type === 'radio' ) {
+ // The default value for checkboxes and radio buttons is 'on'
+ // not ''. By stripping value="" we break radio boxes that
+ // actually wants empty values.
+ if ( $value === 'on' ) {
+ unset( $attribs['value'] );
+ }
+ } elseif ( $type === 'submit' ) {
+ // The default value for submit appears to be "Submit" but
+ // let's not bother stripping out localized text that matches
+ // that.
+ } else {
+ // The default value for nearly every other field type is ''
+ // The 'range' and 'color' types use different defaults but
+ // stripping a value="" does not hurt them.
+ if ( $value === '' ) {
+ unset( $attribs['value'] );
+ }
+ }
+ }
if ( $element === 'select' && isset( $attribs['size'] ) ) {
if ( in_array( 'multiple', $attribs )
|| ( isset( $attribs['multiple'] ) && $attribs['multiple'] !== false )
}
return $cases;
}
+
+ /**
+ * Test out Html::element drops default value
+ * @cover Html::dropDefaults
+ * @dataProvider provideElementsWithAttributesHavingDefaultValues
+ */
+ function testDropDefaults( $expected, $element, $message = '' ) {
+ $this->enableHTML5();
+ $this->assertEquals( $expected, $element, $message );
+ }
+
+ function provideElementsWithAttributesHavingDefaultValues() {
+ # Use cases in a concise format:
+ # <expected>, <element name>, <array of attributes> [, <message>]
+ # Will be mapped to Html::element()
+ $cases = array();
+ $cases[] = array( '<input type="checkbox" />',
+ 'input', array( 'type' => 'checkbox', 'value' => 'on' ),
+ 'Default value "on" is stripped of checkboxes',
+ );
+ $cases[] = array( '<input type="radio" />',
+ 'input', array( 'type' => 'radio', 'value' => 'on' ),
+ 'Default value "on" is stripped of radio buttons',
+ );
+ $cases[] = array( '<input type="submit" value="Submit" />',
+ 'input', array( 'type' => 'submit', 'value' => 'Submit' ),
+ 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
+ );
+ $cases[] = array( '<input type="color" />',
+ 'input', array( 'type' => 'color', 'value' => '' ),
+ );
+ $cases[] = array( '<input type="range" />',
+ 'input', array( 'type' => 'range', 'value' => '' ),
+ );
+
+ # Craft the Html elements
+ $ret = array();
+ foreach( $cases as $case ) {
+ $ret[] = array(
+ $case[0],
+ Html::element( $case[1], $case[2] )
+ );
+ }
+ return $ret;
+ }
+
}