sefianecho / alwan

A simple, lightweight, customizable, touch friendly color picker, written in vanilla javascript with zero dependencies.
https://sefianecho.github.io/alwan/
MIT License
38 stars 6 forks source link

Check if the colors are picked and then enable a button #12

Closed Jonnas123 closed 10 months ago

Jonnas123 commented 10 months ago

How to check if the colors are picked? I disable a button by default <button disabled>Submit</button> And I have two pickers. I want to enable the button if all the two colors from the two pickers are picked.

sefianecho commented 10 months ago

Use the change event.

Jonnas123 commented 10 months ago
pickerOne.on('change', (ev) => {
    document.getElementById('button').disabled = false;
})

This is ok if I have one picker. But I have two pickers. How about to enable the button if the two conditions are met?

sefianecho commented 10 months ago

Try this


let colorOne = '';
let colorTwo = '';
const button = document.getElementById('button');

function enableButton() {
    if (colorOne && colorTwo) {
        button.disabled = false;
    }
}

pickerOne.on('change', (color) => {
    colorOne = color.rgb;
    enableButton();
});

pickerTwo.on('change', (color) => {
    colorTwo = color.rgb;
    enableButton();
});
Jonnas123 commented 10 months ago

Wow, It works, thanks.