Change selected wpColorPicker color with jquery
-
Hello all,
I’m trying to build a color palette system where an admin user can select a predefined palette, which in turn updates all the individual colorpickers already in place. Using Advanced Custom Fields as well with the colorpicker in a repeater field.
Have it working using the below, but it is currently requiring me to do a .submit() in order for the colors to be ‘selected’, ie the color showing up in the preview, etc.
// Process palette change jQuery('#acf-field-selected_palette').change( function(e) { // Remove all existing palette colors jQuery('#acf-palette_colors tr.row').each(function() { this.remove(); }); // Add new colors // - returned val() is like '#000000|#ffffff' var new_palette_colors = jQuery('#acf-field-selected_palette').val().split('|'); jQuery(new_palette_colors).each(function(i,e) { jQuery('#acf-palette_colors a.add-row-end').click(); //acf repeater button adds row jQuery('#acf-palette_colors .acf-color_picker input.color_picker').eq(i).val(this); }); // Submit // - Todo: Find way to update colorpickers instead of having to submit jQuery("form#post").submit(); });
Is there a way I can refresh the colorpicker fields or such instead of having to do the .submit()? Any other suggestions are most welcome!
Thanks much!
Philip
- The topic ‘Change selected wpColorPicker color with jquery’ is closed to new replies.