-1

So I'm writing a Wordpress plugin that generates a live preview upon changes to a php form using ajax. Everything is working great, but one little issue with jQuery is not quite right.

Normally, when you make add any text to a field and then press Enter or click another field, the a function in js is run to update the live preview. For example:

$('#tst-bg_color').on('change.ChangeField', function(){--update preview function here--'});

Yet, I just changed one of my text fields into a Wordpress colorpicker. The field on my php form looks like this now:

<input type="button" name="tst-bg_color[color]" value="" id="tst-bg_color" />

So, not surprisingly this works the same way the other fields work in jQuery, meaning that when you click on another field, it finally runs the "update_preview" function in the jQuery above. However, I'd like to have it run the 'update preview' function each time a new color is selected without the user having to click on another field to update the preview.

I've tried the following, but none of them work:

$('#tst-bg_color').on('click.ChangeField', function(){--update preview function here--'});

and

$('#tst-bg_color').on('mouseup.ChangeField', function(){--update preview function here--'});

Not sure what else I can try to get this to trigger instantly. Any thoughts?

  • Er, keydown?! – bonger Jan 23 '15 at 3:21
  • Are you talking about the Colorpicker that ships with WP Core? – kaiser Jan 25 '15 at 11:26
  • downvoted as this is a JS question, and therefor off-topic here – Mark Kaplun Feb 2 '18 at 6:57
0
  $('yourColorpickerselector').wpColorPicker({
                        change: function(event, ui) {
                            var form = $(this).closest('form')
                            form .trigger('change')
                        }
                    });

within color picker default method "change". you can trigger form change. or any other function, what you want to do.

related link : wordpress discuss iris color picker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.