tags:

views:

149

answers:

3

I've just about got the jPicker script working flawlessly in my app. However, the value it returns contains 8 digits. Example: 212ebcff

Is there a preset variable that forces jPicker to return a 6 digit hex value?

A: 

Unfortunately this was removed from jPicker itself, but it's getting added back next version: see here for details

For now you can just truncate the value with substring, the last ff is the alpha, like this:

val = val.substring(0,6);

or overall using get_Hex in the callback:

$('#Callbacks').jPicker(
  {},
  function(color) {
    alert('Color: #' + color.get_Hex());
  });
});
Nick Craver
Thanks Nick. I'm using the min version of the jPicker.js. Where do I change the value of "val". In the js file I assume, or do I need to intercept the return value before inserting it into my theme options?
Scott B
@Scott - I'd do it in the callback like I have above, or when you're handling the value afterwards...without knowing exactly how you're using it, hard to say which is simpler. Anywhere you have the value and can substring it should work
Nick Craver
I'm calling the jPicker with $(function() { $('#myCustomColor').jPicker(); // the rest of my functions follow. Where do I insert the get_hex conversion and do I simply use $('#myCustomColor').jPicker({}, function(color) {....
Scott B
Nick, I'm not using a custom callback, since I've simply bound the jPicker to an input element (#myCustomColor) the value from the jPicker is automatically updated into my input element.
Scott B
@Scott - I'd say best to either rig up a onchange like this: `$(#myCustomColor).change(function() { if($(this).val().length == 8) $(this).val(function(i, v) { return v.substring(0, 6); }); });` or just substring the value where you're getting/using it.
Nick Craver
A: 

I also wanted to remove the alpha hex codes and I used a substring to do it. Here's how:

In the jpicker.js file (both full and minified) search for "get_Rgba:"
It's on line 531 in the full file (jpicker-1.0.13.js).

Use a substring on this line:

return r != null && g != null && b != null && a != null ? ColorMethods.rgbaToHex({ r: r, g: g, b: b, a: a }) : null;

So that it looks like this:

return r != null && g != null && b != null && a != null ? ColorMethods.rgbaToHex({ r: r, g: g, b: b, a: a }).substring(0, 6) : null;

It's working well for me. Hope this helps others!

Alan Whipple
Thanks Alan, this is an old one so I really appreciate you keeping up with it. I'll try it now.
Scott B
A: 

Hello Scott,

This is Chris Tillman, the developer of the jPicker plugin. I have just published V1.1.0 of the picker which re-includes the alphaSupport variable. Default behavior is now for alphaSupport to be off unless turned on in the settings object. It also will use a 6-digit hex code instead of 8.

This update also includes a reworked internal event model, altering the color values from script (with full visual update), and a little better visual support for IE quirks mode in all versions. There are changes to the Color object that will require small changes in your interaction code, but it is very will documented at http://www.digitalmagicpro.com/jPicker/.

Check out the new code from Google code, just search for jPicker (can only post one link)

Chris Tillman