Page MenuHomePhabricator

HTMLMultiSelect should have a parameter for tooltips
Open, LowPublic

Description

This is so that we can eventually replace the wrongfully-used CheckMatrix in SpecialBotPasswords with a MultiSelect while keeping all of the existing functionality.

Event Timeline

@Volker_E your help is appreciated here.

Below is the snippet of code I am using. As soon as I uncomment the help item in the choices array I get an error message: Catchable fatal error: Method OOUI\HtmlSnippet::__toString() must return a string value in /var/www/html/vendor/oojs/oojs-ui/php/Element.php on line 198

Why is an empty parameter causing that error?

		$out = $this->getOutput();

		$out->setPageTitle( $this->msg( 'boilerplate-helloworld' ) );

		$out->addHelpLink( 'How to become a MediaWiki hacker' );

		$out->addWikiMsg( 'boilerplate-helloworld-intro' );

		$formDescriptor = [

			'choices' => [
				'type' => 'multiselect',
				'options' => [
					'Alphas' => 'alpha',
					'Bravos' => 'bravo',
					'Charlies' => 'charlie'
				],
				//'help' => [],
				'disabled-options' => [ 'bravo' ],
				'default' => [ 'bravo', 'charlie' ],
			],
		];
		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'testform' );

		$htmlForm->setSubmitText( 'Submit Form' );
		$htmlForm->setSubmitCallback( [ 'SpecialHelloWorld', 'trySubmit' ] );

		$htmlForm->show();

If I understand this correctly, each new field in an HTMLForm creates as HTMLFormField which uses a FieldLayout. A FieldLayout is the only element that allows a help attribute that shows up as as icon with a popup. The HTMLMultiselect uses a CheckboxMultiselectInputWidget which uses a single FieldLayout to wrap the label and the checkboxes, and so the help attribute can only take a string, not an array.

$formDescriptor = [
	'choices' => [
		'type' => 'multiselect',
		'options' => [
			'Alphas' => 'alpha',
			'Bravos' => 'bravo',
			'Charlies' => 'charlie'
		],
		'help' => 'Foo bar',
		'disabled-options' => [ 'bravo' ],
		'default' => [ 'bravo', 'charlie' ],
	],
];

This would give you:

Screen Shot 2017-07-25 at 8.10.48 AM.png (125×697 px, 16 KB)


Right now the only way to have a tooltip with every checkbox would be to have separate checkboxes:

$options = [
        'Alphas' => 'alpha',
        'Bravos' => 'bravo',
        'Charlies' => 'charlie'
];

foreach( $options as $label => $data ) {
        $formDescriptor[ $data ] = [
                'type' => 'check',
                'label' => $label,
                'data' => $data,
                'help' => $label, // Something useful here
        ];
}

This would give you:

Screen Shot 2017-07-25 at 8.15.37 AM.png (137×698 px, 15 KB)

WARNING: The form will be encoded in the URL differently in both these cases.

@matmarex How do we want to implement this? Should we add multiple FieldLayouts in CheckboxMultiselectWidget or just add frameless PopupButtonWidgets?

Huji removed Huji as the assignee of this task.May 20 2020, 7:53 PM