X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLForm.php;h=e627cfdc690303e78c04f7e948fdca4ce22e28a0;hb=ea23bc97ee9144c4575fa0bab81a42faa2b1f29c;hp=c65d97f0ff671aeb833f94792b5382a9508576a8;hpb=0e1fd82089e17c45eb81f40dac8c6f6d0e6a4e15;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index c65d97f0ff..e627cfdc69 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -147,6 +147,7 @@ class HTMLForm extends ContextSource { 'namespaceselect' => 'HTMLSelectNamespace', 'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton', 'tagfilter' => 'HTMLTagFilter', + 'sizefilter' => 'HTMLSizeFilterField', 'submit' => 'HTMLSubmitField', 'hidden' => 'HTMLHiddenField', 'edittools' => 'HTMLEditTools', @@ -176,7 +177,7 @@ class HTMLForm extends ContextSource { protected $mFieldTree; protected $mShowReset = false; protected $mShowSubmit = true; - protected $mSubmitFlags = [ 'constructive', 'primary' ]; + protected $mSubmitFlags = [ 'primary', 'progressive' ]; protected $mShowCancel = false; protected $mCancelTarget; @@ -603,10 +604,14 @@ class HTMLForm extends ContextSource { */ public function trySubmit() { $valid = true; - $hoistedErrors = []; - $hoistedErrors[] = isset( $this->mValidationErrorMessage ) - ? $this->mValidationErrorMessage - : [ 'htmlform-invalid-input' ]; + $hoistedErrors = Status::newGood(); + if ( $this->mValidationErrorMessage ) { + foreach ( (array)$this->mValidationErrorMessage as $error ) { + call_user_func_array( [ $hoistedErrors, 'fatal' ], $error ); + } + } else { + $hoistedErrors->fatal( 'htmlform-invalid-input' ); + } $this->mWasSubmitted = true; @@ -633,15 +638,16 @@ class HTMLForm extends ContextSource { if ( $res !== true ) { $valid = false; if ( $res !== false && !$field->canDisplayErrors() ) { - $hoistedErrors[] = [ 'rawmessage', $res ]; + if ( is_string( $res ) ) { + $hoistedErrors->fatal( 'rawmessage', $res ); + } else { + $hoistedErrors->fatal( $res ); + } } } } if ( !$valid ) { - if ( count( $hoistedErrors ) === 1 ) { - $hoistedErrors = $hoistedErrors[0]; - } return $hoistedErrors; } @@ -1041,6 +1047,7 @@ class HTMLForm extends ContextSource { : 'application/x-www-form-urlencoded'; # Attributes $attribs = [ + 'class' => 'mw-htmlform', 'action' => $this->getAction(), 'method' => $this->getMethod(), 'enctype' => $encType, @@ -1054,6 +1061,9 @@ class HTMLForm extends ContextSource { if ( $this->mName ) { $attribs['name'] = $this->mName; } + if ( $this->needsJSForHtml5FormValidation() ) { + $attribs['novalidate'] = true; + } return $attribs; } @@ -1073,7 +1083,7 @@ class HTMLForm extends ContextSource { return Html::rawElement( 'form', - $this->getFormAttributes() + [ 'class' => 'visualClear' ], + $this->getFormAttributes(), $html ); } @@ -1869,4 +1879,22 @@ class HTMLForm extends ContextSource { protected function getMessage( $value ) { return Message::newFromSpecifier( $value )->setContext( $this ); } + + /** + * Whether this form, with its current fields, requires the user agent to have JavaScript enabled + * for the client-side HTML5 form validation to work correctly. If this function returns true, a + * 'novalidate' attribute will be added on the `
` element. It will be removed if the user + * agent has JavaScript support, in htmlform.js. + * + * @return boolean + * @since 1.29 + */ + public function needsJSForHtml5FormValidation() { + foreach ( $this->mFlatFields as $fieldname => $field ) { + if ( $field->needsJSForHtml5FormValidation() ) { + return true; + } + } + return false; + } }