Hi, and thanks for porting this module to D8.

I was trying to use the '#states' element property to conditionally hiding the element, but apparently this is ineffective.

Try the following in a form:

    $form['cccenabled'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enabled'),
      '#default_value' => TRUE,
    ];
    $form['ccc'] = [
      '#type' => 'jquery_colorpicker',
      '#title' => $this->t('Color'),
      '#default_value' => 'FF00FF',
      '#states' => [
        'visible' => [
          ':input[name="cccenabled"]' => ['checked' => TRUE],
        ],
      ],
    ];
    $form['ccd'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Color'),
      '#default_value' => 'FF00FF',
      '#states' => [
        'visible' => [
          ':input[name="cccenabled"]' => ['checked' => TRUE],
        ],
      ],
    ];

Cliking on the checkbox, the 'ccd' textfield visibility is toggled correctly, but the 'ccc' jquery_colorpicker is alyways shown.

AFAICS, the PHP side is correct, I suspect something in the JS side.

Comments

mondrake created an issue. See original summary.

  • Jaypan committed b024313 on 8.x-1.x
    Issue #2849223: #states does not work for the form element
    
jaypan’s picture

Status: Active » Fixed

Fixed in 8.x-1.3 (should be available in about five minutes)

mondrake’s picture

Works great!

Thank you

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.