Added following code to my custom Form and nothing is rendered when form is displayed.
$form['my_field'] = array(
'#type' => 'select_or_other',
'#title' => t('Choose an option'),
'#default_value' => array('value_1'),
'#options' => array(
'value_1' => t('One'),
'value_2' => t('Two'),
'value_3' => t('Three'),
),
'#other' => t('Other (please type a value)'), // Text to show as 'other' option
'#required' => TRUE,
'#multiple' => TRUE,
'#other_unknown_defaults' => 'other', // If the #default_value is not a valid choice in #options, what should we do? Possible values 'append', 'ignore', 'other' (if 'other' specified you can also override #other_delimiter).
'#other_delimiter' => ', ', // Delimiter string to delimit multiple 'other' values into the 'other' textfield. If this is FALSE only the last value will be used.
'#select_type' => 'select', // Defaults to 'select'. Can also be 'radios' or 'checkboxes'.
);
If I change '#type' to 'select' field gets rendered as normal select field.
Any ideas?
Comments
Comment #2
drupalbigot CreditAttribution: drupalbigot as a volunteer and commentedComment #3
sneha_chandole CreditAttribution: sneha_chandole commentedHi,
You can use below code for form api
$form['my_field'] = array(
'#type' => 'select',
'#title' => t('Choose an option'),
'#default_value' => array('value_1'),
'#options' => array(
'value_1' => t('One'),
'value_2' => t('Two'),
'value_3' => t('Three'),
),
'#other' => t('Other (please type a value)'), // Text to show as 'other' option
'#required' => TRUE,
'#multiple' => TRUE,
'#other_unknown_defaults' => 'other', // If the #default_value is not a valid choice in #options, what should we do? Possible values 'append', 'ignore', 'other' (if 'other' specified you can also override #other_delimiter).
'#other_delimiter' => ', ', // Delimiter string to delimit multiple 'other' values into the 'other' textfield. If this is FALSE only the last value will be used.
'#select_type' => 'select', // Defaults to 'select'. Can also be 'radios' or 'checkboxes'.
);
You can use either select, radios or checkboxes type. you can not use select_or_other as type of the form. you can check form api for drupal 8 and related types of the form.
Thanks.
Comment #4
Dubs CreditAttribution: Dubs as a volunteer and at Drupology commentedThis works for me: -
Comment #5
legolasbo8.x-3.x-dev is not under development.
Comment #6
daften CreditAttribution: daften at Dropsolid commentedI updated the link to the External documentation to point to the README file, for which the example does work. Feel free to re-open with a patch if something is still missing.