Issue:
I couldn't seem to figure out how to define a palette for use with the jQuery Spectrum widget. I finally did some digging and found that spectrum expects a Javascript array format as show here: https://bgrins.github.io/spectrum/#options-showPalette
It seems that the current code simply dumps whatever string you enter into the palette field.
So instead of if I wanted a palette of...say: White, Black, Red -- I tried to enter "#ffffff, #000000, #ff0000" sans quotes into the text area provided.
Current code produced...
...
palette: ["#ffffff, #000000, #ff0000"]],
...
This prevented spectrum from producing the proper palette in the widget because the Spectrum code actually needs something like....
...
palette: [["#ffffff", "#000000", "#ff0000"]],
...
So I created a simple patch that implements string to array split on the bar ( | ) character to allow for both hex and rgb values (as commas would break rgb values).
So now my textarea would contain "#ffffff|#000000|#ff0000"
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | color_field_spectrum_palette_fix-2827198-23.patch | 1.98 KB | rwam |
Comments
Comment #2
frogdog_tech commentedComment #4
frogdog_tech commentednew patch against 8.x-2.x-dev and not rc1
Comment #5
frogdog_tech commentedComment #7
frogdog_tech commentedhmm. something broken with automated testing?
Comment #8
mcvjoyner commentedPatch wasn't quite working, also wasn't following file naming convention.
(See comment #9, as correct file is there).
I've uploaded a patch that also fixes the JS issue, when clicking the dropdown, and then clicking anywhere on the page BUT the widget dropdown, it results in a JS error, that reports that it's unable to read from a null reference.
The pacth also addresses the 'description' of the palette widget (textarea) on the the 'manage form display' administration site.
Since we changed the strings to split with the pipe character, it should help the user out by mentioning so.
Description is now:
"Selectable color palette to accompany the Spectrum Widget. Separate values with a pipe (|) character. Example: #ff0000|#00aa00'"
Comment #9
mcvjoyner commentedLooks like the patch in #8 didn't upload correctly. I'm trying again (same patch), as comment #9.
Comment #10
frogdog_tech commented#9 looking good! nice work
Is there any reason you opted to keep the original palette assignment?
palette: [spectrum_settings.palette],Comment #11
frogdog_tech commentedchanging the version to 8.x-2.x-dev
Comment #12
frogdog_tech commentedMods to #9
1. Remove original palette: setting
2. The checkbox (boolean) widget settings didn't seem to be working and were always falling back to defaults. I was unable to activate showInput because showPaletteOnly was stuck on. I evaluate the settings from 1 and 0 to true and false and now the checkbox widget settings are working.
Comment #13
mcvjoyner commented@squidgle, nope no reason, was just not considered :)
Thanks for additions to the patch! #12 Looks good
Comment #14
frogdog_tech commentedComment #16
rwam commentedI really like to set up the palette like described at the example page at http://bgrins.github.io/spectrum/#options-showPalette And I want to use a palette with mulitple rows and my config looks like this:
So please find attached a simple patch which works fine for me.
Comment #17
mcvjoyner commented- Going with tradition here and updating the patch so that files are based on the root of the module itself. (From patch #12).
- Adding in patch #16, cause I think it makes sense, and is pretty clean.
- Updated the help text on the field to reflect and give an example of how the input should look.
Everything seems to work well for me.
Comment #18
mcvjoyner commentedComment #19
rwam commentedHi @cheeky-micah,
the patch works fine for me with 8.x-2.x-rc2. Thanks for updating.
Ciao
Ralf
Comment #20
tamnv commentedHi @cheeky-micah,
The patch works well for me, thanks for updating.
Comment #21
slydevil commentedPatch also works for me - thanks!
Comment #22
rwam commentedPatch 18 failed on new release candidate 8.x-2.0-rc3 and current 8.x-2.x dev branch. After some investigation I've created a new patch to support spectrum palettes again.
Comment #24
rwam commentedHm, I have no idea why the patch failed to apply, but I've updated the patch to use correct translation method.
Comment #26
nickdickinsonwildeThis is a very nice change.
But... it will break existing definitions and needs tests.
Comment #27
nickdickinsonwildeTest and HOOK_post_update_NAME() created.
Comment #29
nickdickinsonwilde(and thanks for doing all the different patch iterations and patience as well as the report)
Comment #32
frogdog_tech commentedThis still fails for RGB since the row explode uses a comma and will break rgba(value,value,value)?