Jump to content

Manual talk:HTMLForm Tutorial 3

Add topic
From mediawiki.org
Latest comment: 12 years ago by Rstockbower in topic htmlform-select-badoption errors

htmlform-select-badoption errors

[edit]

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]

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