问题
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