Is it possible to attach JavaScript event listeners to the colour input field in a plugin's settings page, so that when a user selects a colour with the picker I can run an AJAX request?


If this is your plugin, you can register an AssetBundle with custom CSS and JS for your plugin. This will be loaded in your plugin settings page, and in your JS file you can then specify an event handler for your colour picker. You might need to add a specific class to the input in the settings template to ensure you can select it easily in your JS file.

If this is referring to a first/third-party plugin, you could use a plugin like CP JS to load a custom JS file into the CP and attach an event handler in that file to trigger your XHR.


In the end the problem ended up being that I did not add the event listener to the input elements after the document was ready. The following code fires the eventHandler function correctly when any settings input field is changed, including colour inputs.

$(document).ready(function () {
    $("form :input").change(eventHandler);

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.