選択値に基づいてフィールドをレンダリングしようとしています。しかし、私は今のところ成功できなかったので、ここに私が試したものがあります:
選択フィールド(field_type)でコンテンツタイプを作成しました
var_dump($form['field_type']['und']['#options']);
与える
array (size=5)
'_none' => string '- Select a value -' (length=18)
'externe' => string 'externe' (length=7)
'interne' => string 'interne' (length=7)
'carroussel' => string 'carroussel' (length=10)
'vitrine' => string 'vitrine' (length=7)
私は自分のフィールドを印刷し、このページの最初のコメントを読むことで「und」に気づきました Drupalプロセスは7.xを示します
表示する必要がある(または表示しない)私のフィールド
$form['field_target_text'] = array(
'#type' => 'textfield',
'#default_value' => '',
'#states' => array(
'visible' => array(
'input[name="field_type[und]"' => array('value'=>'interne')
),
),
);
入力をselectに置き換えて[und]を削除しようとしましたが、このようにフィールドを置き換えるまで何もしませんでした
$form['field_type'] = [
'#type' => 'select',
'#title' => ('TYPE TPE'),
'#description' => ('TEST.'),
'#options' => $form['field_type']['und']['#options']
];
彼は私のフィールドに['#options']がなく、['und'] ['#options']が嫌いなようです。ただし、そうすることで、ノードを保存すると、field_typeが空になります。
任意の助けやアドバイスをいただければ幸いです。
セレクター]
で':input[name="field_type[und]"'
を逃すと、次のコードテストが機能します。
':input[name="field_type[und]"]' => ['value' => 'interne'],
更新:
状態は任意の有効なJQueryセレクターで機能するため、:input
の代わりにselect
セレクターでターゲットにしたい場合は、これを使用できます。
'select[name="field_type[und]"]' => ['value' => 'interne'],