Manual talk:HTMLForm Tutorial 3
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()), ),
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