spectrum icon indicating copy to clipboard operation
spectrum copied to clipboard

Color preview should default to placeholder value

Open pascal-hofmann opened this issue 7 years ago • 1 comments

It would be nice if the preview color shown per default (currently black/empty) would default to the value set as placeholder of the input field (if set).

Example:

<input id='colorpicker' placeholder="#123456"/>

Should display the color preview next to the input colored with #123456 if the field itself is empty.

pascal-hofmann avatar Aug 24 '17 16:08 pascal-hofmann

I achieved this by putting the following before initializing spectrum on the field (in my case I was doing an .each() iteration over a number of inputs so $(this) was available):

if(!$(this).val()) $(this).val($(this).attr('placeholder'));

Similar should be able to be accomplished without setting the input value by using the color spectrum initialization option:

color:$(this).val()?$(this).val():$(this).attr('placeholder')

dhjw avatar Jul 29 '19 04:07 dhjw