Optional OptionsetField is SilverStripe 3.2

↘锁芯ラ 提交于 2019-12-23 17:19:09

问题


In SilverStripe 3.1.* I used some forms with OptionsetFields which are optional, so not required to make a choice. This was working well. But since i updated to SilverStripe 3.2.0 the form doesn't accept this anymore. When submit it comes with a validation message, even if I don't use validation in the whole form. See this screenshot:

This is the code of the field:

$ClassField = OptionsetField::create('Class', _t('General.CLASS', "Class"), array(
        "S" => "S",
        "E" => "E",
        "U" => "U",
        "R" => "R",
        "O" => "O",
        "P" => "P"
    ));

Any idea to make this field optional again in SilverStripe 3.2.0 ?


回答1:


This seems to be a bug in 3.2, you have now to tell OptionsetField it can be empty by using setEmptyString():

$ClassField = OptionsetField::create(
    'Class', 
    _t('General.CLASS', "Class"), 
    array(...)
)
->setEmptyString('none');



回答2:


You might be also interested in the silverstripe-display-logic module, which allows you to display certain fields based on some conditions: https://github.com/unclecheese/silverstripe-display-logic



来源:https://stackoverflow.com/questions/33732666/optional-optionsetfield-is-silverstripe-3-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!