Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter aaelghat

    (@aaelghat)

    Hi, one addendum – if absolutely necessary, I could break the form into two separate forms instead of having the conditional, but I’d have to modify your custom JavaScript to remove the reimbursement calculation.

    I tried doing that unsuccessfully (I don’t really know JavaScript), so if I have to break it up into two different forms, could you tell me the JavaScript I would need to use to only calculate the total miles?

    As an alternative to calculating the reimbursement in a script, can that be done as part of the regular Gravity Form number calculation feature since the input is a non-repeater field?

    Thank you again for all your hard work.

    Thread Starter aaelghat

    (@aaelghat)

    Hi – thanks again for all your hard work, but could I get an update? I need to make some decisions about moving ahead.

    Some more information for you:

    I get the same results of the form not rendering when there is a conditional field (reimbursement) outside the repeater with either the latest gravityforms-repeater-development or gravityforms-repeater-master.

    I figured out how to modify the javascript so the number field “Reimbursement” field doesn’t get updated, but whether it gets updated or not I noticed that the attributes of the field don’t stick when the javascript is there. If I try to format the field as currency, it doesn’t retain the setting after the form is saved, and the range of the number is “false” for the min and max.

    I was hoping to do the calculation in the field itself, but that doesn’t work. I can figure out how to format the Reimbursement field as currency in the Javascript (otherwise I get values like $14.580000000000002.

    So really the only issue I can’t overcome is that the form doesn’t render when there is a conditional field on the form. Is there a solution to that? If you could give me an answer today, I will know whether I need to break this up into two nearly identical forms.

    Thanks again.

    Plugin Author Kodie Grantham

    (@kodiegrantham)

    Hey aaelghat! I will look into this today and get back to you. Thank you for your patience.

    Thread Starter aaelghat

    (@aaelghat)

    Terrific – thank you.

    Plugin Author Kodie Grantham

    (@kodiegrantham)

    Hey aaelghat, I’m having trouble recreating the issue. Are you running any other Gravity Forms add-ons?

    Thread Starter aaelghat

    (@aaelghat)

    I am running other add-ons. I will try and clone the site, and turn off some of the other add-ons and see if that makes a difference.

    I do have another question… The javascript that performs the calculation still occasionally results in an “unresponsive script” message. The script is below. Do you have any thoughts on that?

    Thanks!

    <script>
    var gf_miles_formId = 37;
    var gf_miles_repeaterId = 1;
    var gf_miles_childId_milesField = 3;
    var gf_miles_totalMilesId = 11;
    var gf_miles_totalPriceId = 12;
    var gf_miles_pricePerMile = .54;
    
    jQuery('#gform_' + gf_miles_formId).on('gform_repeater_init_done gform_repeater_after_repeat gform_repeater_after_unrepeat gform_repeater_update_price', function(event, repeaterId, repeatId){
    	var milesFields = gfRepeater_select(gf_miles_formId, gf_miles_repeaterId, null, gf_miles_childId_milesField, '*');
    	var totalMiles = 0;
    
    	jQuery.each(milesFields, function(){
    		if (jQuery(this).val()) { totalMiles += Number(jQuery(this).val()); }
    	});
    
    	var totalPrice = '$' + Number(totalMiles * gf_miles_pricePerMile).toFixed(2);
    	jQuery('#input_' + gf_miles_formId + '_' + gf_miles_totalMilesId).val(totalMiles);
    	jQuery('#input_' + gf_miles_formId + '_' + gf_miles_totalPriceId).val(totalPrice);
    
    	updateMilesTrigger(repeatId);
    });
    
    function updateMilesTrigger(repeatId) {
    	var milesField = gfRepeater_select(gf_miles_formId, gf_miles_repeaterId, repeatId, gf_miles_childId_milesField, '*').first();
    
    	jQuery(milesField).on('propertychange change click keyup input paste', function(){
    			jQuery(this).parents('form').trigger('gform_repeater_update_price');
    	});
    }
    </script>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Is there a way to have a conditional field on the form?’ is closed to new replies.