Skip to content

Setting the colour programmatically from outside the picker #76

@mnori

Description

@mnori

I'm building an app with an eye dropper tool that needs to change the colour stored inside the colour picker, from outside the picker. Here's how I'm setting the colour at the moment (not sure if this is the right way to do it!):

var colourPicker = $("#picker_id").colorPicker();
colourPicker.colorPicker.color.setColor(tool.colourFg);
colourPicker.colorPicker.render();

This works, but only after the user has clicked the picker already. If the user hasn't clicked the picker yet, this error occurs:

Uncaught TypeError: Cannot read property '_colorMode' of undefined

This is due to an empty _$trigger variable, which seems to contain the DOM element representing the picker. What I'm looking for is a way to initialise the picker before the user clicks it so that this error does not occur.

I couldn't figure out how to set the _$trigger variable myself as it seems to be encapsulated pretty tight - not that easy to access outside of the picker module.

Here is a jsfiddle that demonstrates the problem:

https://jsfiddle.net/4phnsz7x/19/

If you click the link before clicking the picker, you get the error. If you click the picker first, there is no error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions