Jump to content

Manual talk:HTMLForm Tutorial 3: Difference between revisions

Add topic
From mediawiki.org
Latest comment: 6 months ago by IKhitron in topic Multiselect
Content deleted Content added
Multiselect: new topic
 
(4 intermediate revisions by 3 users not shown)
Line 44: Line 44:
'section' => 'convert-from-section-label',
'section' => 'convert-from-section-label',
'options' => $this->buildOfficeList(),
'options' => $this->buildOfficeList(),
'default' => self::BLANK,
'default' => reset($this->buildOfficeList()),
),</syntaxhighlight>
),</syntaxhighlight>


[[User:Rstockbower|Rstockbower]] ([[User talk:Rstockbower|talk]]) 19:01, 27 September 2012 (UTC)
[[User:Rstockbower|Rstockbower]] ([[User talk:Rstockbower|talk]]) 19:01, 27 September 2012 (UTC)

== HTMLApiField usage ? ==

public static $typeMappings = [
'api' => 'HTMLApiField',

Can this be used for custom html api ?

This code is found in the mediawiki/includes/api/htmlform/HTMLform.php

== Multiselect ==

Hi. Is there a way to add a simple tokens multiselect widget? Like for usermultiselect, but without users, with just a free text tokens. Thank you. [[User:IKhitron|IKhitron]] ([[User talk:IKhitron|talk]]) 14:36, 18 February 2026 (UTC)

Latest revision as of 14:36, 18 February 2026

htmlform-select-badoption errors

[edit source]

If you're building a select dropdown and you're getting htmlform-select-badoption errors, try adding a default value. This array was throwing errors:

Array
(
    [Amsterdam] => AMS
    [Barcelona] => BCN
    [Berlin] => BER
    [Bhiwandi] => BHI
    [Deer Park] => DPK
    [The Hague] => HAG
    [Hong Kong] => HKG
    [Lexington] => LEX
    [Montego Bay] => MBY
    [Mumbai] => MUM
    [Paris] => PAR
    [Silver Spring] => SSM
    [Singapore] => SGP
    [Sydney] => SYD
    [Tunis] => TUN
    [Vadodara] => VAD
    [Venlo] => VEN
    [Windsor] => WND
    [Winterthur] => WTR
)

Copying the array from the tutorial did not throw errors:

Array
(
    [Option 0] => 0
    [Option 1] => 1
    [Option 2] => option2id
)

Note that their structures are the same; one is just a bit more complex than the other.

Making an explicit default got rid of the error message:

'office' => array(
	'name' => 'office',
	'type' => 'select',
	'label' => wfMessage('in-office')->parse(),
	'section' => 'convert-from-section-label',
	'options' => $this->buildOfficeList(),
	'default' => reset($this->buildOfficeList()),
),

Rstockbower (talk) 19:01, 27 September 2012 (UTC)Reply

HTMLApiField usage ?

[edit source]

public static $typeMappings = [ 'api' => 'HTMLApiField',

Can this be used for custom html api ?

This code is found in the mediawiki/includes/api/htmlform/HTMLform.php

Multiselect

[edit source]

Hi. Is there a way to add a simple tokens multiselect widget? Like for usermultiselect, but without users, with just a free text tokens. Thank you. IKhitron (talk) 14:36, 18 February 2026 (UTC)Reply