Skip to main content
code formatting
Source Link
berliner
  • 2.9k
  • 1
  • 21
  • 29

I managed to get it working like this:

**$form['color_select']$form['color_select'] = [
        '#type' => 'radios',
        '#title' => $this->t('Pick a color'),
        '#options' => [
            'blue' => $this->t('Blue'),
            'white' => $this->t('White'),
            'black' => $this->t('Black'),
            // 'other' => $this->t('Other'),
        ],
        '#attributes' => [
            'id' => 'color_select',
            'name' => 'color_select',
        ],
        '#states' => [
            'checked' => [
                ':input[name="color_select"]' => [
                  ['value' => 'blue'],
                  'or',
                  ['value' => 'white'],
                  'or',
                  ['value' => 'black'],
                ],
            ],
        ],
    ];**];

Although I'm not sure how it works now. Does it actually setsset the radio button on checked when the value is one of the given value ones?

I managed to get it working like this:

**$form['color_select'] = [
        '#type' => 'radios',
        '#title' => $this->t('Pick a color'),
        '#options' => [
            'blue' => $this->t('Blue'),
            'white' => $this->t('White'),
            'black' => $this->t('Black'),
            // 'other' => $this->t('Other'),
        ],
        '#attributes' => [
            'id' => 'color_select',
            'name' => 'color_select',
        ],
        '#states' => [
            'checked' => [
                ':input[name="color_select"]' => [
                  ['value' => 'blue'],
                  'or',
                  ['value' => 'white'],
                  'or',
                  ['value' => 'black'],
                ],
            ],
        ],
    ];**

Although I'm not sure how it works now. Does it actually sets the radio button on checked when the value is one of the given value ones?

I managed to get it working like this:

$form['color_select'] = [
  '#type' => 'radios',
  '#title' => $this->t('Pick a color'),
  '#options' => [
    'blue' => $this->t('Blue'),
    'white' => $this->t('White'),
    'black' => $this->t('Black'),
    // 'other' => $this->t('Other'),
  ],
  '#attributes' => [
    'id' => 'color_select',
    'name' => 'color_select',
  ],
  '#states' => [
    'checked' => [
      ':input[name="color_select"]' => [
        ['value' => 'blue'],
        'or',
        ['value' => 'white'],
        'or',
        ['value' => 'black'],
      ],
    ],
  ],
];

Although I'm not sure how it works now. Does it actually set the radio button on checked when the value is one of the given value ones?

Source Link

I managed to get it working like this:

**$form['color_select'] = [
        '#type' => 'radios',
        '#title' => $this->t('Pick a color'),
        '#options' => [
            'blue' => $this->t('Blue'),
            'white' => $this->t('White'),
            'black' => $this->t('Black'),
            // 'other' => $this->t('Other'),
        ],
        '#attributes' => [
            'id' => 'color_select',
            'name' => 'color_select',
        ],
        '#states' => [
            'checked' => [
                ':input[name="color_select"]' => [
                  ['value' => 'blue'],
                  'or',
                  ['value' => 'white'],
                  'or',
                  ['value' => 'black'],
                ],
            ],
        ],
    ];**

Although I'm not sure how it works now. Does it actually sets the radio button on checked when the value is one of the given value ones?