Reputation: 1328
Does anyone know how to find the current value chosen when using the farbtastic color picker? My current code is:
$('#colorpicker').farbtastic('#color');
var curColor = $.farbtastic('#colorpicker').color;
$('#color').change(function () {
curColor = $.farbtastic('#colorpicker').color;
});
I firstly initialise the app and place its contents in a div called colorpicker with the input of #color. I simply want the variable called curColor to hold the current value of the color picker at all times and update as it changes.
Upvotes: 3
Views: 872
Reputation: 3149
Farbtastic allows you to register a callback function to be called when the color is changed. And that is exactly what you need to do. Like that:
$('#colorpicker').farbtastic(function(color) {
console.log('The user has just selected the following color: ' + color);
});
Oh, and if you would like to show the color in an input, or any other element, you can change the previous example to be like that:
$('#colorpicker').farbtastic(function(color) {
console.log('The user has just selected the following color: ' + color);
// setting input value
$('#colorpicker').val(color);
});
Hope that helps.
Upvotes: 5