• Resolved fergsarroca

    (@fergsarroca)


    Hi, hope you are doing good!

    I would like to limit the max and min input value in a number field according to the data that the custumer set into another previus number field.

    I.e:
    If the customer setted it’s 4 people coming to get surf accommodation in number field 1 “number-1” = 4, then not to allow the customer to set 5 people taking surf service in “number-2” and limit it to the “4” of “number 1”.

    I would like the max value limit of “number-2” to be the already introduced value in “number-1”. Is there any chance to?

    Hope i explained myself enough haha.

    Thank for your work.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @fergsarroca,

    I hope you are keeping well.

    Forminator does not offer a ready-made solution for this, and it seems to fall outside the scope of our support. Nevertheless, I’ve inquired with our developers to explore if a workaround could be suggested. We’ll keep you posted here once we receive feedback on this matter.

    Kind Regards,
    Nebu John

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @fergsarroca,

    Hope this message finds you well.

    Our developers provide this code:

    add_action('wp_footer', 'wpmudev_number_limit_application', 9999);
    function wpmudev_number_limit_application() {
    	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(e, form_id) {
    			if ( e.target.id == 'forminator-module-6' ) { // Please change the form ID.
                    $('#number-1 input').on( 'change', function() {
                        var limit = $(this).val();
                        $('#number-2 input').attr('max', limit);
                    });
    			}
    		});
    	});
    	</script>
    	<?php
    }

    Note that you need to update the Form ID and the number fields accordingly, also, this needs to be installed as a mu-plugin, you can follow this guide for it: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Let us know the results.

    Best regards,
    Laura

    Thread Starter fergsarroca

    (@fergsarroca)

    Hi Laura (@wpmudevsupport3),

    Thank you for the provided code snippet. Could you assist me in identifying the specific lines that require modification for updating the Form ID and adjusting the number fields? It would be immensely helpful if you could point out those lines to ensure the correct customization.

    Your assistance is greatly appreciated.

    Best regards, Fernando

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @fergsarroca,

    The lines that require an update are:

    if ( e.target.id == 'forminator-module-6' ) { // Please change the form ID.

    Change number 6 with your form ID.

    If you have a different {number-x} field where x is your source field in your example would be {number-1} is this:

    $('#number-1 input').on( 'change', function() {

    Replace number 1 with the source field number

    For the limited or destination field based on source input, from your example {number-2} would be this line:

    $('#number-2 input').attr('max', limit);

    Replace number 2 with the destination field number.

    Let us know if you require additional information.

    Best regards,
    Laura

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @fergsarroca,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to open a new thread if you have new queries.

    Best Regards
    Nithin

    Thread Starter fergsarroca

    (@fergsarroca)

    Very thanks for your support ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Limit a number field (max&min value) with a previous one.’ is closed to new replies.