views:

600

answers:

3

Hey!

I'm just setting up a web page with a color picker. I choosed farbtastic.

My problem is, that the callback function doesn't work. Here is the code I used:

$('#colorPicker1').farbtastic('#background-color', function callback() { /*commands*/ });

The callback function is not called, when the user choosed a color.

Does someone have a solution?

Thank you! Benedikt

+1  A: 

farbtastic called like you did

$('selector').farbtastic(...)

awaits only one optional argument. This can be a DOM Node, jQuery object, jQuery selector or a function. So you should call the function as shown below

$('#colorPicker1').farbtastic(function(color){
   // commands
});

If you want to use #background-color element, you should use it in the callbacks body

$('#colorPicker1').farbtastic(function(color){
   $('#background-color').css({'background-color':color});
   // commands
});
Rafael
A: 

Yes. I also tried this, but then I don't have the feature of updating the color after loading the page and the text-color switch from black to white.

Is there a simple way to do that? I think coding it manually is not a good way.

Thank you for your answer!

Benedikt R.
Nobody got a solution?
Benedikt R.
A: 

Your post is old I know but just in case :

var picker = $.farbtastic('#colorPicker1');  //picker variable
picker.setColor("#b6b6ff"); //set initial color
picker.linkTo(onColorChange); //link to callback

function onColorChange(color) {
  dosomeStuff();
}
rthriller