问题
I would like to achieve that my field in TCA will be shown or hidden based on my previous field value. How can I do that? I can do it in javascript, but is possible to include a javascript in TCA?
Here user choose value:
$fields = array(
'question_field' => array(
'label' => 'user choose',
'config' => array(
'type' => 'select',
'items' => array(
array('Yes','1'),
array('No','0'),
),
),
)
);
if the value is yes, i would like to display second field:
$fields = array(
'second_field' => array(
'label' => 'second question',
'config' => array(
'type' => 'select',
'items' => array(
array('Yes','1'),
array('No','0'),
),
),
)
);
回答1:
So in your case, it will be adding this line
'displayCond' => 'FIELD:question_field:=:1',
so final solution will looks like this:
$fields = array(
'second_field' => array(
'label' => 'second question',
'displayCond' => 'FIELD:question_field:=:1',
'config' => array(
'type' => 'select',
'items' => array(
array('Yes','1'),
array('No','0'),
),
),
)
回答2:
You need displayCond for that. It‘s well documented with examples in TCA documentation. Please note you can switch TYPO3 version of documentation page bottom left to match your version.
来源:https://stackoverflow.com/questions/43070362/display-field-in-tca-of-pages-based-on-the-previous-field-value