Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

The Color object has no possibility to have no value, it always defaults to #000 #127

Closed
frederikprijck opened this issue Jul 13, 2015 · 6 comments
Labels
Milestone

Comments

@frederikprijck
Copy link

Why is there no option to clear the currently selected color, and make the color optional ? (Or am I missing something?)
Currently it always defaults to black, as described in #87 . Strange to see this issue being closed without the problem itself being adressed.

In my case setting a color is optional. I could work around this using a checkbox to enable/disable the colorpicker. However, I would prefer, from a UX point of view, to enable the user to simply clear his input (or even select NO COLOR from the component).

Using transparant for this is not an option, since transparant is a valid color option aswell. We realy need a way to distinguish no inputs from actual inputs.

Is there a possible workaround? As described in issue 87, the Color class defaults to black due to the following lines:

 var Color = function(val) {
        this.value = {
            h: 0,
            s: 0,
            b: 0,
            a: 1
        };
        this.origFormat = null; // original string format
        if (val) {
            if (val.toLowerCase !== undefined) {
                // cast to string
                val = val + '';
                if (val.charAt(0) !== "#" && (val.length === 3 || val.length === 6)) {
                    val = '#' + val;
                }
                this.setColor(val);
            } else if (val.h !== undefined) {
                this.value = val;
            }
        }
    };

Thanks,

@itsjavi
Copy link
Owner

itsjavi commented Jul 15, 2015

Which version of the plugin are you using?

This was fixed, you can actually have an empty input with no color: http://jsfiddle.net/0vopxm13/
so it is totally optional.
Anyway, could you reproduce the problem as described in the CONTRIBUTING.md guidelines?

Thanks

@frederikprijck
Copy link
Author

Dear,

The sample you provided does indeed support an empty input. Yet it still has a value set as the color.
You can verify the sample here: http://jsfiddle.net/0vopxm13/3/ Just press Click me before setting a color.

I pointed out why the issue is still occuring by specifying which lines of codes are causing the issue. The Color object has no possibility to have no value. And the source code comes from the github repo: https://github.com/mjolnic/bootstrap-colorpicker/blob/master/dist/js/bootstrap-colorpicker.js line 27.

Looking at the sourcecode, I don't see how it can be fixed yet.
We are using the latest version, as you can see in the sample, the issue also exists in the latest version.

Thanks !

@itsjavi
Copy link
Owner

itsjavi commented Jul 15, 2015

I see, the problem is in the API level. This needs a fix, indeed

Thanks for clarifying

@itsjavi itsjavi added the bug label Aug 26, 2015
@itsjavi itsjavi changed the title No way to clear the colorpicker without defaulting to #000 The Color object has no possibility to have no value, it always defaults to #000 Aug 26, 2015
@azza0091
Copy link

azza0091 commented Sep 3, 2015

it would be nice to also have a button to clear the selected color, maybe built inside the color picker...

@itsjavi
Copy link
Owner

itsjavi commented Oct 26, 2015

@azza0091 for doing so you have options that allow you to have custom templates =)

itsjavi pushed a commit that referenced this issue Apr 6, 2016
itsjavi pushed a commit that referenced this issue Apr 9, 2016
@itsjavi itsjavi added this to the v3.0.0 milestone Apr 18, 2016
itsjavi pushed a commit that referenced this issue Sep 16, 2016
@tywalch
Copy link

tywalch commented Sep 8, 2017

While I see this has been closed, is there something I need to do to implemented this? Using the latest, when my field is empty it will assign a value of #000000. I would expect an empty field to remain empty.

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

No branches or pull requests

4 participants