Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resetting jquery minicolors color value

Tags:

jquery

colors

I have successfully implemented minicolors for my site. I've got one problem though, how can i create a new instance of minicolors from click event using a new hex color as a default or new value?

here's how my code looks like:

$('input.minicolors').minicolors({
        change: function(hex, opacity){
            console.log(hex);

        }
    });

//my attempt to recreate the instance, doesn't work

   $('input.minicolors').minicolors({
       value: '#ededed'
   });
like image 453
Saint Dee Avatar asked Jun 02 '13 15:06

Saint Dee


2 Answers

I know this is an old question- but I was trying to do this today and ended up here.

Correct approach for the current version:

First, initialize the input (if new)

$('#someID').minicolors();

Second, change the color

$('#someID').minicolors('value','#00FF00');

Note: you can't combine initializing and setting the color in the same step. However, you can pre-set the color by storing it in the value of the input.

like image 173
Mike Emery Avatar answered Nov 11 '22 22:11

Mike Emery


Look at their documentation:

settings

Gets or sets a control's settings. If new settings are passed in, the control will destroy and re-initialize itself with any new settings overriding the old ones.

I conclude from that, the following will do what you want:

$('input.minicolors').minicolors('settings', {
  value: '#ededed'
});
like image 25
akhikhl Avatar answered Nov 11 '22 23:11

akhikhl