Limit number of option in multiple selection checkbox

This topic contains 12 replies, has 4 voices, and was last updated by  Naveen Giri 3 years, 11 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #537966

    periwinkle
    Expired Member
    Post count: 29

    There is a way to limit the number of option an user can select in a specific multiple selection checkbox?
    I need that the user can selected only two option.

    #537978

    Kor
    Moderator
    Post count: 16516

    Hi periwinkle,

    Thanks for your post. There isn’t an option that allows you to achieve that. A workaround would be to create another “multiple selection checkbox” with a limited “checkboxes” and assign it on different pricing packages.

    #537991

    periwinkle
    Expired Member
    Post count: 29

    Hi,
    thank you for your reply.

    I’m sorry but I dont understand how your suggestion could help me.

    Maybe I don’t have explain my needs very well.
    I have one checkbox with four option (a, b, c, d). Normally users can select all of them, I want that they can select only two (for example only “a” and “b”, or “a” and “c” etc…)

    #538055

    Alex Rollin
    Moderator
    Post count: 27815

    There isn’t a setting for that. I will ask the developers if there is a way to validate multi-select fields like that.

    #538552

    Naveen Giri
    Moderator
    Post count: 1559

    Hi periwinkle,

    there is no existing validation for it.
    could you share the page URL.
    let us know about the field you are talking about.

    Thanks

    #538733

    periwinkle
    Expired Member
    Post count: 29
    This reply has been marked as private.
    #538745

    Naveen Giri
    Moderator
    Post count: 1559

    Hi periwinkle,

    Seems I don’t have access of that page.
    Please share login details in a private reply.

    Thanks

    #538748

    periwinkle
    Expired Member
    Post count: 29
    This reply has been marked as private.
    #538863

    Naveen Giri
    Moderator
    Post count: 1559

    Hi periwinkle,

    Please use this snippet.
    you can use https://wordpress.org/plugins/code-snippets/ plugin.

    
    
    
    add_action( 'wp_head', function () { ?>
    <script>
    
    	/* write your JavaScript code here */
    jQuery(document).ready(function() {
    
        var last_valid_selection = null;
    
        jQuery('#orario_evento_2').change(function(event) {
    
        jQuery('#orario_evento_2').change(function(event) {
            if (jQuery(this).val() && jQuery(this).val().length > 2) {
    
                jQuery(this).val(last_valid_selection);
            } else {
                last_valid_selection = jQuery(this).val();
            }
        });
        });
    });
    
    </script>
    <?php } );
    

    Thanks

    #538867

    periwinkle
    Expired Member
    Post count: 29

    Thank you so much!!Perfect.

    There is only one little bug, when I click on the “x” icon it doesn’t clear the options already selected but it still remain one. It is possible to solve it?

    #538883

    Naveen Giri
    Moderator
    Post count: 1559

    Hi periwinkle,

    I have updated the code above and also changed it on your site.
    Please have a look.

    Thanks

    #538918

    periwinkle
    Expired Member
    Post count: 29

    Thank you! It solved the problem!

    #538924

    Naveen Giri
    Moderator
    Post count: 1559

    You’re Welcome, have a great day.

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

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket