Setting the colorpicker default

Status
Not open for further replies.

zebrafilm

Member
I am using a DB with RAL colors, name and color hexvalue.
When someone sets a RAL color I would like to switch a color square to that color too.

1. Is it possible to set the colorpicker to a color from/by another element?
 
Yes. All Fabrik elements have an update() method in their Javascript class. The colourpicker takes three arguments, the r, g and b values, so update('255','0','0') would turn it red.

You access the element's object through the main block for that form, so if your form's ID is 123, and your element is called yourtable___picker ...

Code:
Fabrik.getBlock('form_123').formElements.get('yourtable___picker').update('255','0','0');

So you just need to change the form and element names, and set the r, g and b args as appropriately.

-- hugh
 
Great, wil try but I need to look up that value from the DB.

I am not good with Javascript can an object be set from PHP?

Then I can use a calc element like:

$S=(int)'{truck1___Spuitkleur_raw}'; //get the selected color / lookup iD
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select ('(RGBcode)')
->from('duc_spuiten')
->where('id='.$S);

$db->setQuery($query);
$S1 = $db->loadResult(); // set the found RGB code for displaying

Set the colorpicker and

return $S1;


IF I need to use JS, where exactly does it need to be entered?
 
you can't set the colour picker directly from PHP, You would need to use a combination of both javascript and PHP to do what you need.
We have a pretty well documented script here: components/com_fabrik/user_ajax_example.php which walks you through the process of attaching an event to an onchange event, triggering an ajax call to the server and then returning the response back to the browser.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top