Git Product home page Git Product logo

Comments (7)

claviska avatar claviska commented on July 23, 2024

I'll see what I can come up with.

from jquery-minicolors.

Cyriltra avatar Cyriltra commented on July 23, 2024

Hi,

I faced the same issue and did a quick fix:
in updateFormControl() function, in Handle Color parts, I changed:

input.val( convertCase(hex, settings.letterCase) );

by

var rgb = hex2rgb(hex),
opacity = input.attr('data-opacity');
if(opacity && input.minicolors('rgbObject').a < 1 && rgb)
input.val('rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')');
else{
input.val( convertCase(hex, settings.letterCase) );
}

Basically, if Opacity value = 1, then the input value will be in HEX format. But if Opacity value < 1, then the input value will be in RGBA format

Also i noticed the input value is updated if color is changed (with mousemouse), but not if Opacity is changed. Thus I also changed the selector:

if( target.is('.minicolors-grid, .minicolors-slider,') ) {

by

if( target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider') ) {

from jquery-minicolors.

claviska avatar claviska commented on July 23, 2024

I don't believe that's what the original poster was asking about. It sounds like he wants to accept an RGB(A) value in the value method. It looks like you're trying to show the RGB(A) value in the input element.

from jquery-minicolors.

chrismadrigal avatar chrismadrigal commented on July 23, 2024

I will probably say both of this cases are very useful. Currently I will like to be able to input and RGBA color on the field and also have the value attribute be change to that. I there any way I can do that?
Thanks... Great plugin.

from jquery-minicolors.

claviska avatar claviska commented on July 23, 2024

RGB(A) isn't as user-friendly as hex colors, but for those who need it, feel free to submit a pull request. It will have to be thorough, since the plugin was only built to parse/output hex color strings.

For those who just need to get the RGB(A) value, the rgbObject method will be useful:

$('input').minicolors('rgbObject') ---> Object {r: 255, g: 97, b: 97, a: .5}

I also thought of a simple algorithm for parsing RGB(A) strings in case it helps:

  1. Start with an RGB(A) string: rgba(10, 20, 30, .5)
  2. Remove everything that's not a number, period, or comma: 10,20,30,.5
  3. Split at the comma: [10, 20, 30, .5]
  4. Check each element for validity (e.g. 0-255 for colors, 0-1 for opacity)

from jquery-minicolors.

cyrezdev avatar cyrezdev commented on July 23, 2024

Hi all!

I have created a PR to allow rgba values input (and additionally, i have added the possibility to activate css color keywords (transparent, inherit, initial).
#170

Testing and feedback welcome!
Cyril

from jquery-minicolors.

claviska avatar claviska commented on July 23, 2024

See #170 for further discussion.

from jquery-minicolors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.