Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use vanilla-picker within forms? #34

Closed
oldcastlehq opened this issue Jul 28, 2020 · 2 comments
Closed

How to use vanilla-picker within forms? #34

oldcastlehq opened this issue Jul 28, 2020 · 2 comments

Comments

@oldcastlehq
Copy link

I think this question is related to the issue #20.

If I cannot use the picker with an input filed, how can I have it in a form?
I need to save the color that the user picks in my DB. So, I need the picker within a form. Is that possible?

@oldcastlehq oldcastlehq changed the title How to use vailla-picker within forms? How to use vanilla-picker within forms? Jul 28, 2020
@Sphinxxxx
Copy link
Owner

Keep a hidden input field in your form, and update its value when the color changes:

var picker = new Picker({
    parent: pickerParent,
    color: 'gold',
    onChange: function(color) {
        pickerParent.style.backgroundColor = color.rgbaString;

        //Update the form's hidden input field:
        colorField.value = color.hex;
    },
});

https://codepen.io/Sphinxxxx/pen/KKVLxmm

@oldcastlehq
Copy link
Author

It works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants