How to add colorpicker to a form textfield

This is how you can add colorpicker to a form textfield for instance in your theme settings file.

<?php
  drupal_add_css
('misc/farbtastic/farbtastic.css');
 
drupal_add_js('misc/farbtastic/farbtastic.js');

 
$form['color'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Color pickmeup'),
   
'#default_value' => '#123456',
   
'#description' => '<div id="colorpicker"></div>',
  );

 
$form['colorpicker_example'] = array(
   
'#type' => 'item',
   
'#description' => "<script type='text/javascript'>
    $(document).ready(function() {
      $('#colorpicker').farbtastic('#edit-color');
    });
    </script>"
,
  );
  return
$form;

?>
Knowledge keywords: