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

useAlpha changes formats from RGBA to RGB if alpha is 1 #322

Open
Genkilabs opened this issue Dec 7, 2020 · 2 comments
Open

useAlpha changes formats from RGBA to RGB if alpha is 1 #322

Genkilabs opened this issue Dec 7, 2020 · 2 comments

Comments

@Genkilabs
Copy link

Description

If the config useAlpha=true has been set, an alpha value of 1 is excluded from the result. This is a bug because it means that the tool returns RGBA formatted data only when there is an alpha value less than one, but if the alpha is 1 (100% opaque) then the result format is changed to simple RGB.

While this functionality may be acceptable for some loosely-defined use cases (web designers), it is opinionated compared to earlier versions of colorpicker and now violates the rule of lease surprise.

If this is truly intended(?) by the author, there should be a way to enforce that the format selected in the options is the one used. ie. forceFormat: true

Context

  • bootstrap-colorpicker version: 3.2.0
  • bootstrap version: 4.5.3
  • jQuery version: 3.5.1
  • Browser name and version: Crome/Brave Chromium 87.0.4280.88 (Official Build) (x86_64)
  • Operative System name an version: OSX 10.15.7

Expected behavior

The flags userAlpha and format when used in combination should ALWAYS set the result value to an RGBA formatted string.

	$('.colorpicker').colorpicker({
		format: "rgba",
		useAlpha: true
	});

Actual behavior

The format of the returned string becomes RBG (no alpha) if the alpha value is 1

Live Example

This is visible on the project's own demo page on any of the examples that return RGB(and sometimes A)
https://itsjavi.com/bootstrap-colorpicker/tutorial-Basics.html

@Genkilabs
Copy link
Author

FYI This arose because my current use case for the tool is for data entry of engineering specs. Web designers and artists don't really care if the results are consistent, but if you record the form results in a data set to be used by an engineer or hard scientist, then mixed formats result in errors.
Of course you can do some regexp massage on the results to add a 1, but that is not ideal.

(If there is agreement in this change I would be willing to make a PR)

@itsjavi
Copy link
Owner

itsjavi commented Apr 23, 2021

I would also expect it to be rgba if you explicitly define the format, even with alpha = 1
A PR would be very welcome

sorry for the late reply

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

No branches or pull requests

2 participants