• Resolved partaim

    (@partaim)


    Hello,

    i have a form with checkboxes. In the last two checkboxes, i need users to choose 8 options for each checkbox, not more, not less. I added this code in a php file (mu-plugins) as described in other similar topics: https://gist.github.com/wpmudev-sls/5be7b5f7eac4132e1539b850b8ab751c

    The code works perfectly as regards the maximum limit of 8 choices, but I don’t know how to set the minimum limit: even by selecting 7, 6, 5 etc. the form allows me to go to the next step. How do I limit the choices so that they are necessarily 8, no more and no less?

    Thank you!

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @partaim

    I hope you are doing well today.

    Can you export your form, upload it to Google Drive, and share a link in your next reply so that we can be on the same page? Also, attach in Google Drive screenshots about which fields we are talking about as the site URL you have shared seems to be in the Italian language and password protected.

    Kind Regards,
    Kris

    Thread Starter partaim

    (@partaim)

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi partaim

    Thank you for the additional data. I pinged our SLS Team so that they can dig into this issue further for you. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter partaim

    (@partaim)

    Hi Kris,

    thank you, i’ll wait for you! ??

    Thread Starter partaim

    (@partaim)

    Hi,

    do you have any news about the problem? Thank you in advance! ??

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @partaim

    I apologize for long response. We’ve missed relevant e-mail notification on our end, I’m really sorry about that.

    Please make following change in the code that you tried (this one):

    replace this (it’s part of line 66)

    _selected >= _forminator_restrict_multiple_fields.limit[ _parent_id ]

    with this

    _selected < _forminator_restrict_multiple_fields.limit[ _parent_id ]

    Best regards,
    Adam

    Thread Starter partaim

    (@partaim)

    Hi Adam,

    don’t worry, it happens sometimes! ??

    By the way, i tried the code above, but i’m still able, in checkbox-11, to proceed to the next checkbox (checkbox-12) even if i checked less than 8 options. Meanwhile, the previous 10 checkboxes, for which I set a limit of 1 check and which previously worked correctly, now allow me to select more options. I’m losing sleep over it! :’)

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @partaim

    Thank you for understanding!

    I’m sorry that this change didn’t help. I got it directly from our developers but maybe they missed something. I have asked them to double-check it again and I’m awaiting their response.

    I’d appreciate a bit more patience (again, sorry for keeping you waiting!) and we’ll update you here again soon.

    Best regards,
    Adam

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @partaim,

    Hope this message finds you well and sorry for our delay.

    Our devs shared this new code:

    add_action( 'wp_footer', 'wpmudev_limit_validation_checkbox', 9999 );
    function wpmudev_limit_validation_checkbox() {
    	global $post;
        if ( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'forminator_form' ) ) {
            return;
        }
    	?>
    	<script type="text/javascript">
    	jQuery( document ).ready( function($){
    		setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
    		},100);
    
    		$(document).on('after.load.forminator', function(event, form_id) {
    			$.validator.addMethod("min_selection", function (value, element) {
    				let parent = $(element).closest('.wpmudev-checkbox-limit');
                    let selected = parent.find(':checkbox:checked').length;
                    if ( selected == 8 ) { // Exact selection limit here.
                        return true;
                    }
                    return false;
    			},"Please select 8 options.");
    			$( ".wpmudev-checkbox-limit input" ).attr( "min_selection", "min_selection" );
    		});
    	});
    	</script>
    	<?php
    }

    You might also need to add this class wpmudev-checkbox-limit in the styling tab of the checkbox field where you want exactly 8 selections.

    Let us know the results.

    Best regards,
    Laura

    Thread Starter partaim

    (@partaim)

    It worksss!!!

    You are awesome guys, thank you SO MUCH!!!! You just made my day ??

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @partaim,

    Glad to hear it works, I am marking this as solved.

    If you have any additional questions or require further help, please let us know!

    Best regards,
    Laura

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Set a minimum choice limit in checkboxes’ is closed to new replies.