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'
});
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.
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'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With