itsjavi / bootstrap-colorpicker

Bootstrap Colorpicker is a modular color picker plugin for Bootstrap.
https://itsjavi.com/bootstrap-colorpicker/
MIT License
1.38k stars 367 forks source link

Synchronizing multiple colorpickers #289

Closed RouNNdeL closed 5 years ago

RouNNdeL commented 5 years ago

I'm trying to synchronize the values across multiple colorpickers when the user checks a checkbox. Right now every method that updates the colorpicker triggers the onchange event thus causing a RangeError: Maximum call stack size exceeded. Is there any way to update the visuals of the picker without an event firing?

itsjavi commented 5 years ago

did you try using event.stopPropagating()?

RouNNdeL commented 5 years ago

I was using 3.0.0-beta at the time. Since then the new change event isn't triggered when using setValue (colorpickerChange is). So I manged to achieve the effects without event.stopPropagating(). For anyone that comes across (any improvements to this code are welcome):

$(COLORPICKER_SELECTOR).on('change', function(e) {
    if(update_all) {
        $(COLORPICKER_SELECTOR).not($(this)).colorpicker("setValue", e.value);
    }
}).colorpicker(COLORPICKER_OPTIONS);
itsjavi commented 5 years ago

yes I remember now it was fixed, sorry for the late response

RouNNdeL commented 5 years ago

Thanks for the response by the way. Gave it another go, to double check that event.stopPropagating() solution, and I have it working now thanks to that :)