How i can limit Taxonomy Multi Select input?
I create Field with this setting :
Field Type* = Taxonomy
Field Type = Multiple Values – Multi Select
Load & Save Terms to Post = checked
I display the form in the front end. i already success to limit multiple values – checkbox, but i have a problem to limit Multi Select Dropdown.
Can you help me?
Hi @adechriz
Thanks for the question. This is possible by hooking in and modifying the select2 parameters. ACF contains a JS filter which you can use like so:
<script type="text/javascript">
(function($) {
acf.add_filter('select2_args', function( args, $select, settings ){
// limit to 3
args.maximumSelectionSize = 3;
// return
return args;
});
})(jQuery);
</script>
This code is untested but should work if you place it on the page with your form. You may need to check the $select (jquery object) and test if it is the correct select field.
Thanks
E
Thank You @Elliot Condon
I’ll do trial and error based on your code and select2.js documentation
and I’ll submit the working code here..
hello @RaZz
yes, it actually works, i just paste that code above and it works like a charm..
For anyone looking, select2 has changed maximumSelectionSize
to maximumSelectionLength
. An updated version of the above:
(function($) {
acf.add_filter('select2_args', function( args, $select, settings ){
// limit to 3
args.maximumSelectionLength = 3;
return args;
});
})(jQuery);
This is great.
I would love to see this integrated natively. It is a very powerful enhancement.
Also added PER FIELD instead of it just applying the limit of 3 to every taxonomy drop down selection. (I guess you can just target by class name)
The topic ‘Limit Taxonomy Multi Select Dropdown’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.