* @note This widget is not likely to remain functional in non-OOUI forms.
*/
class HTMLUsersMultiselectField extends HTMLUserTextField {
-
public function loadDataFromRequest( $request ) {
- if ( !$request->getCheck( $this->mName ) ) {
- return $this->getDefault();
- }
+ $value = $request->getText( $this->mName, $this->getDefault() );
- $usersArray = explode( "\n", $request->getText( $this->mName ) );
+ $usersArray = explode( "\n", $value );
// Remove empty lines
$usersArray = array_values( array_filter( $usersArray, function( $username ) {
return trim( $username ) !== '';
} ) );
- return $usersArray;
+ // This function is expected to return a string
+ return implode( "\n", $usersArray );
}
public function validate( $value, $alldata ) {
return false;
}
- foreach ( $value as $username ) {
+ // $value is a string, because HTMLForm fields store their values as strings
+ $usersArray = explode( "\n", $value );
+ foreach ( $usersArray as $username ) {
$result = parent::validate( $username, $alldata );
if ( $result !== true ) {
return $result;
return true;
}
- public function getInputHTML( $values ) {
+ public function getInputHTML( $value ) {
$this->mParent->getOutput()->enableOOUI();
- return $this->getInputOOUI( $values );
+ return $this->getInputOOUI( $value );
}
- public function getInputOOUI( $values ) {
+ public function getInputOOUI( $value ) {
$params = [ 'name' => $this->mName ];
if ( isset( $this->mParams['default'] ) ) {
->plain();
}
- if ( !is_null( $values ) ) {
- $params['default'] = $values;
+ if ( !is_null( $value ) ) {
+ // $value is a string, but the widget expects an array
+ $params['default'] = explode( "\n", $value );
}
// Make the field auto-infusable when it's used inside a legacy HTMLForm rather than OOUIHTMLForm