*
* Options:
* - columns
- * - Required list of columns in the matrix.
+ * - Required associative array mapping column labels (as HTML) to their tags.
* - rows
- * - Required list of rows in the matrix.
+ * - Required associative array mapping row labels (as HTML) to their tags.
* - force-options-on
- * - Accepts array of column-row tags to be displayed as enabled but unavailable to change
+ * - Array of column-row tags to be displayed as enabled but unavailable to change.
* - force-options-off
- * - Accepts array of column-row tags to be displayed as disabled but unavailable to change.
+ * - Array of column-row tags to be displayed as disabled but unavailable to change.
* - tooltips
- * - Optional array mapping row label to tooltip content
+ * - Optional associative array mapping row labels to tooltips (as text, will be escaped).
* - tooltip-class
* - Optional CSS class used on tooltip container span. Defaults to mw-icon-question.
+ * Not used by OOUI form fields.
*/
class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable {
static private $requiredParams = [
'id' => $this->mID,
'rows' => $this->mParams['rows'],
'columns' => $this->mParams['columns'],
- 'tooltips' => $this->mParams['tooltips'],
+ 'tooltips' => $this->mParams['tooltips'] ?? [],
'forcedOff' => $this->mParams['force-options-off'] ?? [],
'forcedOn' => $this->mParams['force-options-on'] ?? [],
- 'values' => $value
+ 'values' => $value,
] + OOUI\Element::configFromHtmlAttributes( $attribs )
);
}
*
* @param array $config Configuration array with the following options:
* - columns
- * - Required list of columns in the matrix.
+ * - Required associative array mapping column labels (as HTML) to their tags.
* - rows
- * - Required list of rows in the matrix.
+ * - Required associative array mapping row labels (as HTML) to their tags.
* - force-options-on
- * - Accepts array of column-row tags to be displayed as enabled but unavailable to change
+ * - Array of column-row tags to be displayed as enabled but unavailable to change.
* - force-options-off
- * - Accepts array of column-row tags to be displayed as disabled but unavailable to change.
+ * - Array of column-row tags to be displayed as disabled but unavailable to change.
* - tooltips
- * - Optional array mapping row label to tooltip content
- * - tooltip-class
- * - Optional CSS class used on tooltip container span. Defaults to mw-icon-question.
+ * - Optional associative array mapping row labels to tooltips (as text, will be escaped).
*/
public function __construct( array $config = [] ) {
// Configuration initialization
$tr->appendContent( $this->getCellTag( "\u{00A0}" ) );
foreach ( $this->columns as $columnLabel => $columnTag ) {
$tr->appendContent(
- $this->getCellTag( $columnLabel )
+ $this->getCellTag( new \OOUI\HtmlSnippet( $columnLabel ) )
);
}
$table->appendContent( $tr );
* Get a formatted table row for the option, with
* a checkbox widget.
*
- * @param string $label Row label
+ * @param string $label Row label (as HTML)
* @param string $tag Row tag name
* @return \OOUI\Tag The resulting table row
*/
$labelField = new \OOUI\FieldLayout(
new \OOUI\Widget(), // Empty widget, since we don't have the checkboxes here
[
- 'label' => $label,
+ 'label' => new \OOUI\HtmlSnippet( $label ),
'align' => 'inline',
] + $labelFieldConfig
);
/**
* Get an individual cell tag with requested content
*
- * @param string $content Content for the <td> cell
+ * @param mixed $content Content for the <td> cell
* @return \OOUI\Tag Resulting cell
*/
private function getCellTag( $content ) {
*
* @constructor
* @param {Object} [config] Configuration options
- * @cfg {Object} columns Required object representing the column labels and associated
- * tags in the matrix.
- * @cfg {Object} rows Required object representing the row labels and associated
- * tags in the matrix.
- * @cfg {string[]} [forcedOn] An array of column-row tags to be displayed as
- * enabled but unavailable to change
- * @cfg {string[]} [forcedOff] An array of column-row tags to be displayed as
- * disnabled but unavailable to change
- * @cfg {Object} Object mapping row label to tooltip content
+ * @cfg {Object} columns Required object mapping column labels (as HTML) to
+ * their tags.
+ * @cfg {Object} rows Required object mapping row labels (as HTML) to their
+ * tags.
+ * @cfg {string[]} [forcedOn] Array of column-row tags to be displayed as
+ * enabled but unavailable to change.
+ * @cfg {string[]} [forcedOff] Array of column-row tags to be displayed as
+ * disabled but unavailable to change.
+ * @cfg {Object} [tooltips] Optional object mapping row labels to tooltips
+ * (as text, will be escaped).
*/
mw.widgets.CheckMatrixWidget = function MWWCheckMatrixWidget( config ) {
var $headRow = $( '<tr>' ),
this.forcedOff = config.forcedOff || [];
// Build header
- $headRow.append( $( '<td>' ).html( ' ' ) );
+ $headRow.append( $( '<td>' ).text( '\u00A0' ) );
// Iterate over the columns object (ignore the value)
$.each( this.columns, function ( columnLabel ) {
- $headRow.append( $( '<td>' ).text( columnLabel ) );
+ $headRow.append( $( '<td>' ).html( columnLabel ) );
} );
$table.append( $headRow );
labelField = new OO.ui.FieldLayout(
new OO.ui.Widget(), // Empty widget, since we don't have the checkboxes here
{
- label: rowLabel,
+ label: new OO.ui.HtmlSnippet( rowLabel ),
help: widget.tooltips[ rowLabel ],
align: 'inline'
}