Viewing 1 replies (of 1 total)
  • Plugin Author ovann86

    (@ovann86)

    Hey,

    I don’t have the time to take on new work at the moment, but if you develop or commission the work I’ll be happy to look at adding it into the plugin so others can benefit from the features.

    I’m not entirely clear on what you’re trying to achieve and how they relate to drop down fields, but if you’re looking for file uploading using the repeating ‘list’ field – check out one of my other plugins … Ajax Upload for Gravity Forms

    As for the price summing – I’ev done some custom JavaScript that does this … it’s tricky to work around all the various ways dollars can be entered (with or without $ symbol, with or without decimal place, force decimal place behaviour (none or to two places), ensure dollar symbol, comma, decimal place, numbers only in the field — including when type or pasted into the field. Lots of different ways you have to make sure it wont break.

    Basically, the JS took a column, took every value in it, clensed the value using the rules above so it was numbers only, added it up and dumped it in another field (ie, not the same list).

    Might think about making another plugin that uses the JS some time in the future.

    I’ll paste the JS I used below, but it would need to be ammended for your rules (things I mentioned above) and made specific for your forms (the JS directly references a form and field IDs)

    <script>
    jQuery(document).on("blur", ".gfield_list_119_cell2 input", function(e) {
    jQuery(this).val(two_decimal_places(jQuery(this).val()));
    });
    
    var two_decimal_places = function(num){
    if (num !== '') {
      num = num.toString().replace(/,/g,'');
      num = parseFloat(num).toFixed(2);
    if (isNaN(num)) {
     return '';
    }else
    {
    return(format(num));
    }
    }
    };
    
    jQuery.fn.ForceNumericOnly =
    function()
    {
        return this.each(function()
        {
            jQuery(this).keydown(function(e)
            {
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
                // home, end, period, and numpad decimal
                return (
                    key == 8 ||
                    key == 9 ||
                    key == 13 ||
                    key == 46 ||
                    key == 110 ||
                    key == 190 ||
                    (key >= 35 && key <= 40) ||
                    (key >= 48 && key <= 57) ||
                    (key >= 96 && key <= 105));
            });
        });
    };
    
    jQuery(".gform_body").ready(
    itsp_gf_total_cost_function()
    );
    
    jQuery(document).on("click", ".add_list_item", function(){
    			itsp_gf_total_cost_function()
    		});
    
    jQuery(document).on("click", ".delete_list_item", function(){
    			itsp_gf_total_cost_function();
    		});
    
    jQuery(document).on("keyup", ".gfield_list_119_cell2 input", function() {
          itsp_gf_total_cost_function();
    });
    
    jQuery(document).on("keyup", ".gfield_list_119_cell2 input", function(e) {
    
    jQuery(this).val(format(jQuery(this).val())); 
    
        });
    
    function itsp_gf_total_cost_function(){
    jQuery(".gfield_list_119_cell2 input").ForceNumericOnly();
        var sum = 0;
        jQuery(".gfield_list_119_cell2 input").each(function(){
    
            sum += +jQuery(this).val() .replace(/\,/g,"");
        });
        jQuery("#input_28_121").val(numberWithCommas(sum));
    }
    
    function numberWithCommas(x) {
    //x = Math.floor(x);  // remove decimal place
    x =  Math.floor(x * 100) / 100;  // to two decimal places
    if (isNaN(x)) {
     return '';
    }else
    {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); // make comma separated and return value
    }
    }
    
    var format = function(num){
    var str = num.toString().replace(/[0-9\.]/g, "");
    	var str = num.toString().replace("$", ""), parts = false, output = [], i = 1, formatted = null; // remove $ symbol
    
    	if(str.indexOf(".") > 0) {
    		parts = str.split(".");
    		str = parts[0];
    	}
    	str = str.split("").reverse();
    	for(var j = 0, len = str.length; j < len; j++) {
    		if(str[j] != ",") {
    			output.push(str[j]);
    			if(i%3 == 0 && j < (len - 1)) {
    				output.push(",");
    			}
    			i++;
    		}
    	}
    	formatted = output.reverse().join("");
    	return(formatted + ((parts) ? "." + parts[1].substr(0, 2) : ""));
    
    };
    </script>
Viewing 1 replies (of 1 total)
  • The topic ‘other features’ is closed to new replies.