Skip to content

Color field not working #179

Closed
Closed

Description

@richardsweeney

The color picker doesn't work. I tried adding it to a repeater field and to a single field but it's not working. You can't pick a different color.

colorpicker

  • Browser: Chrome (51)
  • Papi: 3.1.3
  • WordPress: 4.5.3

Activity

  1. frozzare commented on Jul 29, 2016

    @frozzare
    Member

    I think there is a problem with the color picker in wp, I will take another look at this and see if I can do anything in Papi to fix it.

  2. nlemoine commented on Oct 21, 2016

    @nlemoine
    Contributor

    I can confirm this issue too. I'm currently looking into it.

    Here's what I found out:

    1 - There's an issue with palettes property.
    Default is an array: https://github.com/wp-papi/papi/blob/master/src/properties/class-papi-property-color.php#L16
    If no settings are provided, this returns an empty array to the palettes property of the options object passed to wpColorPicker. Default should be true.

    2 - There's another issue (palettes are buggy when clicked) caused by this: https://github.com/wp-papi/papi/blob/master/src/assets/js/properties/color.js#L44-L46
    Is there any reason you want to trigger change on the input? I didn't look deeper but looks like no function is binded to this event.

    Actually, some options in papi doesn't exist in wpColorPicker: https://github.com/WordPress/WordPress/blob/master/wp-admin/js/color-picker.js#L13-L20
    Is there a reason here too?

  3. frozzare commented on Oct 21, 2016

    @frozzare
    Member
    1. yep, will take a look at the color picker for 3.2
    2. I think this was a solution for a older version of wordpress, maybe not needed anymore.
    3. Not all options that exists in papi is options for the color picker, the property can have own options, so that's isn't a problem.
  4. frozzare commented on Oct 23, 2016

    @frozzare
    Member
    1. The palettes options that will give a a empty array isn't a problem since it's checked in the js code https://github.com/wp-papi/papi/blob/f546c80/src/assets/js/properties/color.js#L44
    2. Removed the double change event and it's seems that it works better. Could you try it out @nlemoine or @richardsweeney? (3.x branch)
    3. What about adding all options that exists for wpColorPicker to the property? (maybe not the target option)
  5. added this to the v3.1.16 milestone on Oct 24, 2016
  6. self-assigned this
    on Oct 24, 2016
  7. nlemoine commented on Oct 24, 2016

    @nlemoine
    Contributor

    1 - If palettes array is empty, palettes should return true, not false (I think most people expect the ability to choose colors, not only some colors from black to white):
    !palettes.length ? true : palettes
    But even when passing true to palettes, an empty array is still passed to iris: https://github.com/WordPress/WordPress/blob/master/wp-admin/js/color-picker.js#L58. If you take a look at WordPress color picker code, options passed to wpColorPicker are merged with the ones found in element data: https://github.com/WordPress/WordPress/blob/master/wp-admin/js/color-picker.js#L31
    And Papi uses a data attributes named data-palettes to get the palettes array. So the empty array found in data attributes overrrides the true value returned by Papi.

    So there's no need to pass palettes (or any other options) through papi JS, these lines could actually be removed:

    const palettes = $el.data().palettes;

    palettes: palettes === undefined || !palettes.length ? false : palettes

    The only thing you need is set the data attribute data-palettes on the input element accordingly:

    'data-palettes' => $settings->palettes,

    'data-palettes' => $settings->palettes ? $settings->palettes : true,

    And eventually other options could be passed as data-dattributes.

    2 - Yes, this resolves the palettes click issue.

    3 - Why not. What's the target option, I can't see it? https://github.com/WordPress/WordPress/blob/master/wp-admin/js/color-picker.js#L13-L21

  8. frozzare commented on Oct 24, 2016

    @frozzare
    Member
    1. Wow, why is the standalone version of wpColorPicker different from the build in, so bad. The documentation of iris.js says false on palettes.
    2. Good.
    3. Same as 1, the standalone version of wpColorPicker is different from WordPress's. But adding all options that are relevant isn't so hard, just time consuming :)
  9. frozzare commented on Oct 25, 2016

    @frozzare
    Member
    1. Should be right now according to wpColorPicker and not iris.js since the diff.
    2. Created a new issue for adding all options to 3.2.0 instead of 3.1.16. Add all color picker options to color property #202
  10. nlemoine commented on Oct 25, 2016

    @nlemoine
    Contributor

    Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions