I've implemented colorpicker in one of my modules, however, I have recently come up against an issue where the colorpicker_textfiled and colorpicker do not link themselves together. I've narrowed the problem down to setting #tree = true on one of the form elements parents.

  $form['attributes'] = array(
      '#type' => 'markup',
      '#value' => ' ',
      '#tree' => TRUE, //the offending line
      );
  $form['attributes']['Color']['color00_colorpicker'] = array(
    '#type' => 'colorpicker',
    '#title' => t('Color 00'),
    );
  $form['attributes']['Color']['color00'] = array(
    '#type' => 'colorpicker_textfield',
    '#default_value' => ($attributes['color12'] ? $attributes['color12'] : '#A186BE'),
    '#colorpicker' => 'color00_colorpicker',
    );

When #tree is false the id of the colorpicker text field is "edit-color00", but when #tree is true, the id changes to "edit-attributes-Color-color00"

Comments

aaron1234nz’s picture

Status: Active » Fixed

Don't worry, solved it.

I needed to write

  $form['attributes']['Color']['color00'] = array(
    '#type' => 'colorpicker_textfield',
    '#default_value' => ($attributes['color12'] ? $attributes['color12'] : '#A186BE'),
    '#colorpicker' => 'attributes_Color_color00_colorpicker',
    );
Anonymous’s picture

Status: Fixed » Closed (fixed)

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