Color picker in 5.7

Permalink
I'm working on converting one of my personal add-ons for 5.7 and it automatically uses the new color picker. When editing the block, how do you clear the picker so that no color is chosen?

1 Attachment

mhawke
 
formigo replied on at Permalink Reply
formigo
Good question - been wondering this ourselves...

Not sure you can currently. :(
JohntheFish replied on at Permalink Reply
JohntheFish
You certainly could clear the colour with the spectrum picker I put together and released as a 5.6 addon.

I built that before the underlying infrastructure of 5.7 changed, so I don't know how much of it actually found its way into the 5.7 code. Its not an area of 5.7 I have gone into since the release.
goutnet replied on at Permalink Reply
5.7 uses spectrum.

you can instanciate your spectrum directly or modifiy the options so that "allowEmpty" is true.

for instance:

$('#myid').spectrum({allowEmpty:true});


or (if you have it already created)

$('#myid').spectrum('option', 'allowEmpty', true );
mhawke replied on at Permalink Reply
mhawke
Thanks for the tip but I couldn't get this to work from the block files. I tried adding it to a $(document).ready routine in edit.php but it had no effect so I dug into the core color.php file and added

$options['allowEmpty'] = true;

to the option list which worked.

I'd rather not hack the core or have to figure out how to override the color.php file so is there a way to do this from within the block files?
shahroq replied on at Permalink Reply
shahroq
This color picket issue fixed at the pull #1279 and will be released at the next version:
https://github.com/concrete5/concrete5-5.7.0/pull/1279...
mhawke replied on at Permalink Reply
mhawke
Thanks but that breaks things. $options is not defined when it's merged with $defaults so I get this error message:
array_merge() [function.array-merge]: Argument #2 is not an array
mhawke replied on at Permalink Reply
mhawke
It looks like it was the way I my legacy block was calling the color.php function. It seems the API has changed for that.

It used to take 4 parameters like this:
public function output($fieldFormName, $fieldLabel, $value = null, $includeJavaScript = true)

but now it takes only 3 and you can send it your own options from the block which is nice:

public function output($inputName, $value = null, $options = array()) {

It would be nice if it was allowed us to send it options AND didn't break all the existing color picker calls.
goutnet replied on at Permalink Reply
Well,

I am affraid the porting task is quite a cumbersome one … lot of things like that happen :/
mhawke replied on at Permalink Reply
mhawke
I'm not naive about the size of the task but it should be well understood that the main barrier to 5.7's adoption will be the complete lack of compatible add-ons so I'm suggesting that more effort should be given to making new functions as compatible as possible to speed up the development of new add-ons. I have it working now. Thanks for the pointers.