Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save faisalahammad/78a0ce01affaef10ab8d4858a5c7dd0d to your computer and use it in GitHub Desktop.

Select an option

Save faisalahammad/78a0ce01affaef10ab8d4858a5c7dd0d to your computer and use it in GitHub Desktop.
Fix Ninja Forms Multi-Select option selection Issue. Prevent Default Selection & Enable Proper Multi-Select Handling in Forms.
jQuery(document).ready(function($) {
function fixMultiSelect() {
$('select[multiple].ninja-forms-field:not([data-fixed])').each(function() {
$(this).attr('data-fixed', 'true')
.on('mousedown', function(e) {
e.preventDefault();
if (e.target.tagName === 'OPTION') {
var $opt = $(e.target);
$opt.prop('selected', !$opt.prop('selected'));
$(this).trigger('change').trigger('input');
}
})
.on('click', function(e) {
e.preventDefault();
});
});
}
var attempts = 0;
var maxAttempts = 50;
function waitAndFix() {
attempts++;
if ($('select[multiple].ninja-forms-field').length > 0) {
fixMultiSelect();
}
if (attempts < maxAttempts) {
setTimeout(waitAndFix, 200);
}
}
waitAndFix();
$(document).ajaxComplete(function() {
setTimeout(fixMultiSelect, 100);
});
});
@faisalahammad
Copy link
Author

Preview:

CleanShot 2025-08-04 at 15 50 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment