Improve handling of the required argument in HTMLForm field definitions
authorjeroendedauw <jeroendedauw@gmail.com>
Sat, 11 Aug 2012 22:23:46 +0000 (00:23 +0200)
committerjeroendedauw <jeroendedauw@gmail.com>
Sat, 11 Aug 2012 22:26:17 +0000 (00:26 +0200)
array( 'required' => false ) will now result in the field not being required rather then the unexpected opossite.

And this is now possible (without doing some extra if)

array( 'required' => getSomeBoolean() )

Change-Id: I1fc22b16ab1fa17111c48aa664aaf47de5f7075a

includes/HTMLForm.php

index ce9c377..e617f17 100644 (file)
@@ -1109,7 +1109,7 @@ abstract class HTMLFormField {
         * @return Mixed Bool true on success, or String error to display.
         */
        function validate( $value, $alldata ) {
-               if ( isset( $this->mParams['required'] ) && $value === '' ) {
+               if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value === '' ) {
                        return wfMsgExt( 'htmlform-required', 'parseinline' );
                }
 
@@ -2153,7 +2153,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        return $p;
                }
 
-               if ( isset( $this->mParams['required'] ) && $value[1] === '' ) {
+               if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value[1] === '' ) {
                        return wfMsgExt( 'htmlform-required', 'parseinline' );
                }