有人可以帮助我在SilverStripe 3的DropdownField
中将空白设置为默认值吗?
当前这是我的代码:
DropdownField::create(
'HowHear',
'How did you hear of this job?',
array(
'Indeed' => 'Indeed',
'Caterer' => 'Caterer',
'Gumtree' => 'Gumtree',
'Word of mouth' => 'Word of mouth',
'Other' => 'Other',
)
)->addExtraClass('full-width'),
答案 0 :(得分:6)
在SilverStripe 3和4中,DropdownField
具有函数setEmptyString('')
,该函数将设置默认的空字符串:
DropdownField::create(
'HowHear',
'How did you hear of this job?',
[
'Indeed' => 'Indeed',
'Caterer' => 'Caterer',
'Gumtree' => 'Gumtree',
'Word of mouth' => 'Word of mouth',
'Other' => 'Other',
]
)->addExtraClass('full-width')->setEmptyString('')