SilverStripe DropdownField的默认值设置为空白

时间:2018-10-12 13:45:38

标签: php dropdown silverstripe

有人可以帮助我在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'),

1 个答案:

答案 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('')