• Resolved tax50

    (@tax50)


    I would like the calculated field to display as 0 if the result of the calculation is less than 0. So for example if 10-20 is less than 0 then display 0 in the calculated field. Please help.

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @tax50

    I hope you are doing well today.

    By default, this will be not possible as the calculation engine needs to work correctly according to mathematical principles.

    I pinged our SLS Team to check if we can do something in this matter. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter tax50

    (@tax50)

    Thank you Kris, the help is genuinely appreciated.

    Hi again @tax50

    add_action( 'wp_footer', 'wpmudev_fix_calculation_negative_value', 9999 );
    function wpmudev_fix_calculation_negative_value() {
    	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) {
                if ( event.target.id = 'forminator-module-6' ) { //Please change the form ID
                    $('#calculation-1 input').on('change', function() { //Please change the field ID
                        var calc_field = $(this);
                        var calc_val = $(this).val();
                        setTimeout(function(){
                            if ( calc_val < 0 ) {
                                calc_field.val(0);
                            }
                        });
                    });
                }
            });
        });
        </script>
        <?php
    }

    Form ID(forminator-module-6) and Calculation field ID(#calculation-1) should be managed in the snippet.

    Kind Regards,
    Kris

    Thread Starter tax50

    (@tax50)

    Thank you Kris I will try that tonight and get back to you.

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @tax50 ,
    
    We haven’t heard back from you for several days now, so it looks like you no longer need our assistance.
    
    Feel free to re-open this topic if needed.
    
    Kind regards
    Kasia

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Create a special calculation’ is closed to new replies.