Created
August 4, 2025 09:49
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preview: