wiki.techinc.nl/includes/htmlform/HTMLComboboxField.php
Bartosz Dziewoński ee5af95167 HTMLForm: Use OOUI\Element::configFromHtmlAttributes instead of rolling our own
Depends on I0e5c956b9358b510c8473b1cfe6465ea1b5c07ef in OOjs UI.

This mostly reverts dd04b31052 and parts
of e85bd04bcd.

In addition to cleanup, it fixes bugs in HTMLFormFieldWithButton
(which did not add some attributes in OOUI mode) and HTMLMultiSelectField
(which did not do the mapping, losing some attributes in OOUI mode).

Change-Id: I0d1a5288e9edb73a0c3a8431feca9fcc67b72b6a
2016-03-09 00:08:05 +00:00

59 lines
1.6 KiB
PHP

<?php
/**
* A combo box field.
*
* You can think of it as a dropdown select with the ability to add custom options,
* or as a text field with input suggestions (autocompletion).
*
* When JavaScript is not supported or enabled, it uses HTML5 `<datalist>` element.
*
* Besides the parameters recognized by HTMLTextField, the following are
* recognized:
* options-messages - As for HTMLSelectField
* options - As for HTMLSelectField
* options-message - As for HTMLSelectField
*/
class HTMLComboboxField extends HTMLTextField {
// FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
public function getAttributes( array $list ) {
$attribs = [
'type' => 'text',
'list' => $this->mName . '-datalist',
] + parent::getAttributes( $list );
return $attribs;
}
function getInputHTML( $value ) {
$datalist = new XmlSelect( false, $this->mName . '-datalist' );
$datalist->setTagName( 'datalist' );
$datalist->addOptions( $this->getOptions() );
return parent::getInputHTML( $value ) . $datalist->getHTML();
}
function getInputOOUI( $value ) {
$disabled = false;
$allowedParams = [ 'tabindex' ];
$attribs = OOUI\Element::configFromHtmlAttributes(
$this->getAttributes( $allowedParams )
);
if ( $this->mClass !== '' ) {
$attribs['classes'] = [ $this->mClass ];
}
if ( !empty( $this->mParams['disabled'] ) ) {
$disabled = true;
}
return new OOUI\ComboBoxInputWidget( [
'name' => $this->mName,
'id' => $this->mID,
'options' => $this->getOptionsOOUI(),
'value' => strval( $value ),
'disabled' => $disabled,
] + $attribs );
}
}