From a83188d0ab6768849e2879692de764a16fa652b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 2 Dec 2016 18:28:30 +0100 Subject: [PATCH] HTMLFormFieldCloner: Set 'formnovalidate' on add/remove field buttons Otherwise, after we allow HTML5 form validation attributes, these buttons wouldn't work for non-JS users (unless the whole form was otherwise valid). Change-Id: Ia9c16849774c186b991280ea60fc5608ddd4cf42 --- includes/htmlform/fields/HTMLButtonField.php | 10 ++++++++++ includes/htmlform/fields/HTMLFormFieldCloner.php | 3 +++ 2 files changed, 13 insertions(+) diff --git a/includes/htmlform/fields/HTMLButtonField.php b/includes/htmlform/fields/HTMLButtonField.php index 500b5020c8..a19bd5a1e4 100644 --- a/includes/htmlform/fields/HTMLButtonField.php +++ b/includes/htmlform/fields/HTMLButtonField.php @@ -13,6 +13,9 @@ * of the value from 'default'. Overrides 'buttonlabel-raw'. * - buttonlabel-raw: HTMLto display for the button display text, instead * of the value from 'default'. + * - formnovalidate: Set to true if clicking this button should suppress + * client-side form validation. Used in HTMLFormFieldCloner for add/remove + * buttons. * * Note that the buttonlabel parameters are not supported on IE6 and IE7 due to * bugs in those browsers. If detected, they will be served buttons using the @@ -27,12 +30,18 @@ class HTMLButtonField extends HTMLFormField { /** @var array $mFlags Flags to add to OOUI Button widget */ protected $mFlags = []; + protected $mFormnovalidate = false; + public function __construct( $info ) { $info['nodata'] = true; if ( isset( $info['flags'] ) ) { $this->mFlags = $info['flags']; } + if ( isset( $info['formnovalidate'] ) ) { + $this->mFormnovalidate = $info['formnovalidate']; + } + # Generate the label from a message, if possible if ( isset( $info['buttonlabel-message'] ) ) { $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse(); @@ -71,6 +80,7 @@ class HTMLButtonField extends HTMLFormField { 'type' => $this->buttonType, 'name' => $this->mName, 'value' => $this->getDefault(), + 'formnovalidate' => $this->mFormnovalidate, ] + $this->getAttributes( [ 'disabled', 'tabindex' ] ); if ( $this->isBadIE() ) { diff --git a/includes/htmlform/fields/HTMLFormFieldCloner.php b/includes/htmlform/fields/HTMLFormFieldCloner.php index abb50d0918..8fb840a136 100644 --- a/includes/htmlform/fields/HTMLFormFieldCloner.php +++ b/includes/htmlform/fields/HTMLFormFieldCloner.php @@ -57,6 +57,7 @@ class HTMLFormFieldCloner extends HTMLFormField { if ( isset( $this->mParams['fields']['delete'] ) ) { $class = 'mw-htmlform-cloner-delete-button'; $info = $this->mParams['fields']['delete'] + [ + 'formnovalidate' => true, 'cssclass' => $class ]; unset( $info['name'], $info['class'] ); @@ -310,6 +311,7 @@ class HTMLFormFieldCloner extends HTMLFormField { : 'htmlform-cloner-delete'; $field = HTMLForm::loadInputFromParameters( $name, [ 'type' => 'submit', + 'formnovalidate' => true, 'name' => $name, 'id' => Sanitizer::escapeId( "{$this->mID}--$key--delete" ), 'cssclass' => 'mw-htmlform-cloner-delete-button', @@ -382,6 +384,7 @@ class HTMLFormFieldCloner extends HTMLFormField { : 'htmlform-cloner-create'; $field = HTMLForm::loadInputFromParameters( $name, [ 'type' => 'submit', + 'formnovalidate' => true, 'name' => $name, 'id' => Sanitizer::escapeId( "{$this->mID}--create" ), 'cssclass' => 'mw-htmlform-cloner-create-button', -- 2.20.1