bgrins / spectrum

The No Hassle JavaScript Colorpicker
https://bgrins.github.io/spectrum/
MIT License
2.32k stars 588 forks source link

Change does not fire if submit is pressed without changing the color #403

Open stephen304 opened 8 years ago

stephen304 commented 8 years ago

JSFiddle: https://jsfiddle.net/53gy1tyq/2/

If you open the picker and click submit, no event is fired. If you open the picker, move the selector, then slick submit, the change event is fired.

I want the user to be able to select the default color by opening the picker and pressing submit without changing the color, and it seems like this should be the way it works.

I guess it does make sense to have a change event that only fires when the color is changed from what it was, maybe there should be a submit event that fires every time submit is pressed, whether the color is the same or changed?

avoliva commented 8 years ago

Change is not fired because nothing is changed.

You may want to check out the hide event.

stephen304 commented 8 years ago

Hide fires both when the user clicks out of the box and when they press submit. The main issue I see is that there is no event that lets you trigger an action when the user opens the color picker and presses submit without changing the color.

avoliva commented 8 years ago

It's a good point and the docs do state it's fired when the 'Choose' button is clicked or the input is closed.

Also with clickoutFiresChange, clicking outside also fires a change just like a hide.

https://github.com/bgrins/spectrum/blob/master/spectrum.js#L873

Right there is where the event is fired. You could get rid of the hasChanged boolean, and I believe that would fire every time submit is clicked.

stephen304 commented 8 years ago

Thanks for the tip. Basically right now I'm using the change event to submit the values. If there were an event that fired if and only if the submit button was pressed, I would use that instead.

For now I'll just make that edit on L873.

avoliva commented 8 years ago

You should open a PR too, if you wish.

avoliva commented 8 years ago

Looks like this guy may have already beat you to it.

stephen304 commented 8 years ago

I think it might make more sense to have a separate submit event, since I agree it doesn't make much sense to have change fire if the color didn't change and was just submitted.