1
所以我有我的表單中的元素列表,其中之一是一個簡單的是/否選項的選擇框。當該字段爲「否」時,我想使下一個輸入字段成爲必需。ZF2只根據另一個元素創建一個表單元素?
此刻我的輸入濾波器的樣子:
return [
[
'name' => 'condition',
'required' => true,
],
[
'name' => 'additional',
'required' => false,
'validators' => [
[
'name' => 'callback',
'options' => [
'callback' => function($value, $context) {
//If condition is "NO", mark required
if($context['condition'] === '0' && strlen($value) === 0) {
return false;
}
return true;
},
'messages' => [
'callbackValue' => 'Additional details are required',
],
],
],
[
'name' => 'string_length',
'options' => [
'max' => 255,
'messages' => [
'stringLengthTooLong' => 'The input must be less than or equal to %max% characters long',
],
],
],
],
],
];
什麼我發現是因爲我有'required' => false,
爲additional
場,沒有validators
運行。
僅當condition
爲'no'(值'0')時,我該如何製作additional
?