I’m trying to add custom palette support to my ACF color pickers.
I’ve tried the following method called in acf/input/admin_enqueue_scripts:
acf.add_action('ready append', function( $el ){
var palette = ['#f9e0c5', '#dcc6b2', '#f9ebe1', '#344857'];
acf.get_fields({ type : 'color_picker'}, $el).each(function(){
$(this).iris('option', 'palettes', palette);
});
});
But the following error is thrown:
cannot call methods on iris prior to initialization; attempted to call method ‘option’
The following code adds the palette as expected, however (strangely) the color picker stops selecting the correct color when interacting with the draggable gradient. Not sure why.
<?php function load_color_palette_options() {?>
<script>
jQuery(document).ready(function($){
var palette = ['#f9e0c5', '#dcc6b2', '#f9ebe1', '#344857'];
if ($('.acf-color_picker').length) {
$('.acf-color_picker').iris({
palettes: palette
});
}
});
</script>
<?php }
add_action( 'admin_print_footer_scripts', 'load_color_palette_options' );?>
Anyone got a suggestion as to what’s the best way to add a custom color picker palette to ACF5 color-picker fields without breaking its functionality?