We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

MD Color Picker outputting RGB colors instead of HEX

Development and Programming

stubear's avatar
stubear
114 posts
15 years ago
stubear's avatar stubear

Is there a way to get MD Color Picker to output RGB colors instead of HEX? I poked through the fieldtype code but nothing I tried worked. The field displayed “[object Object]” when I changed this line from:

$("input[name='.$this->field_name.']").val(hex);

to this:

$("input[name='.$this->field_name.']").val(rgb);

and this line from:

$("input", cell).val(hex);

to this:

$("input", cell).val(rgb);

The preceding line in both instances was:

onSubmit: function(hsb, hex, rgb) {

so I had assumed the value was available but apparently not. Any ideas?

       
Aegir's avatar
Aegir
2 posts
13 years ago
Aegir's avatar Aegir

So it’s years since you asked but I just wondered exactly this. Since I just got it working I thought I’d best post the answer in case anyone else needs it.

The javascript stores the rgb values as an object, so you need to get each of the properties for red, green and blue separately and output them together as a string. This outputs them with a comma between them:

$("#'.$field_name.'").val(rgb.r + "," + rgb.g + "," + rgb.b);

This replaces line 54 of the PHP, which is currently this:

$("#'.$field_name.'").val(hex);

Hope that helps someone.

       
stubear's avatar
stubear
114 posts
13 years ago
stubear's avatar stubear

Thanks Aegir. It has been a while but this will be handy info to have on future projects.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.