Support

Account

Home Forums ACF PRO Limit Taxonomy Multi Select Dropdown

Solved

Limit Taxonomy Multi Select Dropdown

  • 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?

    • Elliot

    • September 2, 2014 at 10:33 am

    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

    • adechriz

    • September 2, 2014 at 10:48 am

    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..

    • RaZz

    • September 29, 2014 at 1:46 am

    Hey,

    did you get it to work?

    Best regards!

    • adechriz

    • September 29, 2014 at 11:14 am

    hello @razz
    yes, it actually works, i just paste that code above and it works like a charm..

    • puncle

    • August 2, 2017 at 12:25 am

    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);	
    
    • wp16

    • June 1, 2021 at 7:19 pm

    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)

    @elliot

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.