Search code examples
drupaldrupal-8drupal-modules

drupal 8 conditional field with link field


I am trying to work a conditional field based on the value input in a link field. For example, based on an external or internal link. I couldn't find a proper example, but the ones I found, I have tried this, no luck. Any idea how this can work -

$form['field_test_1']['#states'] = [
      'visible' => [
        ':input[name="field_test_2[widget][0][uri][#default_value]"]' => 'https://www.google.com',
      ],
    ];

Solution

  • ok so I have worked it out, it should be like this -

    $form['field_test_1']['#states'] = [
          'visible' => [
            ':input[name="field_test_2[0][uri]"]' => [ 'value' => 'https://www.google.com' ],
          ],
        ];