'relative' => false,
'creatable' => false,
'exists' => false,
+ // This overrides the default from HTMLFormField
+ 'required' => true,
];
parent::__construct( $params );
if ( $this->mParent->getMethod() === 'get' && $value === '' ) {
// If the form is a GET form and has no value, assume it hasn't been
// submitted yet, and skip validation
+ // TODO This doesn't look right, we should be able to tell the difference
+ // between "not submitted" (null) and "submitted but empty" (empty string).
return parent::validate( $value, $alldata );
}
+
+ if ( !$this->mParams['required'] && $value === '' ) {
+ // If this field is not required and the value is empty, that's okay, skip validation
+ return parent::validate( $value, $alldata );
+ }
+
try {
if ( !$this->mParams['relative'] ) {
$title = Title::newFromTextThrow( $value );
if ( $params ) {
$msg->params( $params );
}
- return $msg->parse();
+ return $msg;
}
$text = $title->getPrefixedText();
if ( $this->mParams['namespace'] !== false &&
!$title->inNamespace( $this->mParams['namespace'] )
) {
- return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text )->parse();
+ return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text );
}
if ( $this->mParams['creatable'] && !$title->canExist() ) {
- return $this->msg( 'htmlform-title-not-creatable', $text )->escaped();
+ return $this->msg( 'htmlform-title-not-creatable', $text );
}
if ( $this->mParams['exists'] && !$title->exists() ) {
- return $this->msg( 'htmlform-title-not-exists', $text )->parse();
+ return $this->msg( 'htmlform-title-not-exists', $text );
}
return parent::validate( $value, $alldata );