Is there a way to update the Gravity Forms total from a separate JavaScript file? I’m using the following script to count the uploads from the Smart Uploads addon for Gravtiy Forms. It keeps track of the uploads, and adds the count to the quantity field.
The script works fine, however the number inserted by the script doesn’t effect the total. The total only updates if an option is changed within the form, or if you manually type into the quantity field (due to it running something on keyup / keydown judging by the console).
Is there anything I could add to the botton of this script to update the total?
// Select the node that will be observed for mutations
const targetNode = $(`[name="fileuploader-list-files"]`)[0];
// Options for the observer (which mutations to observe)
const config = { attributes: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.attributeName === 'value') {
let fileCount = (function(){
try {
return JSON.parse(targetNode.value).length;
} catch (e) {
return 0;
}
}())
// Adds the file count to the quantity input
document.getElementById("input_2_12").value = fileCount;
// I need something here to update the Gravtiy Forms total
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
I’m using a number field with a calculation for my total. It looks like this:
<ul>
<li id="field_2_27" class=
"gfield gforms-total gfield_calculation field_sublabel_below field_description_below gfield_visibility_visible">
<label class="gfield_label" for="input_2_27">Total</label></li>
</ul>
<div class="ginput_container ginput_container_number">
<input name="input_27" id="input_2_27" type="text" value="" class="small" tabindex=
"4" readonly="readonly" aria-invalid="false" />
</div>