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

Huji created this task.Jun 23 2017, 2:08 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 23 2017, 2:08 PM
Huji added a subscriber: Volker_E.Jul 7 2017, 9:03 PM

@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:


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:

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?