sylvainjule / kirby-color-palette

A color palette to pick colors from in the panel. Kirby 3 only.
57 stars 9 forks source link

Enable structured colors with dynamic options #17

Open Benjamin-Bach opened 3 years ago

Benjamin-Bach commented 3 years ago

Hi Sylvain Great job this plugin. I'm trying to use dynamic options from a structured field. For the color, it works, but the tooltip does not get the name. What am I missing?

My color-palette field:

type: color-palette
options: query
query:
   fetch: site.colors.toStructure
   value: "{{structureItem.color}}"
   tooltip: "{{structureItem.name}}"

My structured field:

label: Colors used within pages
type: structure
fields:
   name:
     type: text
     label: Name
   color:
     extends: fields/styles/color

Thank you

bnomei commented 3 years ago

@sylvainjule how to do that?

sylvainjule commented 2 years ago

The plugin uses the core Query functions, which sanitizes the query result and returns only the text / value pair. This will probably require switching to a dedicated query method, I'll try to implement it soon.

arnoson commented 1 year ago

Is it just me are has this stopped working (trying it in Kirby 3.9.5)

arnoson commented 1 year ago

I found the issue: to determine wether the options are from a query, you are testing Object.keys(option).length == 2 (https://github.com/sylvainjule/kirby-color-palette/blob/master/src/components/field/ColorPalette.vue#L147). In recent versions of Kirby, the option has more keys: disabled, icon, info, text, value. I have no idea where they come from, but removing the length check should solve the issue. Or is there a particular reason your are checking for the length? Of course we could just check for a length of 5, but this could break again in future versions.

I can create a PR (but I had to switch from parcel to kirbyup, since I couldn't get it running with parcel).