+/- buttons not updating/triggering totals field

By: Andres Garcia | Asked: 10/28/2022
ForumsCategory: General questions+/- buttons not updating/triggering totals field
Andres Garcia asked 1 year ago

I run a restaurant and what to be able to take inventory of how much I have in soft drink syrup for fountain drinks. I'm creating a dropdown to select the flavor, and have recorded the weight of a full container. I'll then weigh an open/partially dispensed unit, and its a simple math formula to figure out what is remaining, know these 2 figures. I am using Chris Adam's code to add large +/- buttons to record full units. Here is my problem: When I enter a weight amount in the partial weight field, it behaves correctly the and Total field updates. Updating the syrup flavor from the dropdown will also trigger the Total field to recalculate. However, when I use the +/- butons, the Total field isnt triggered/upddated. How can I make this work?   https://connect.formidableforms.com/question/category/code-snippets/add-large-and-buttons-to-number-inputs/

Attachments
Rob LeVineRob LeVine replied 1 year ago

Can you provide a link to a live or test site showing the page?

4 Answers
Bobby Clapp answered 1 year ago

I've dealt with this recently. When something is triggered programmatically you have to initiate a trigger on that programmed event before you can do something. I believe what I did was this.

$(selector).trigger("change"); //The field to watch changes for. Here selector should be the calculated field element ID

Then:
$(selector).on("change", function(){ //Here selector should be the calculated field element ID
//What to do here
});

Rob LeVineRob LeVine answered 1 year ago
Using Bobby's idea, you can try adjusting the code like this and see if that works.  The code additions are in bold.

< script > jQuery(".myNum").each(function () { var j = jQuery; //Just a variable for using jQuery without conflicts var addInput = (this); var n = 0; //n is equal to 0 //Set default value to n (n = 0) j(addInput).val(n); //On click add 1 to n j(this).next("span").on('click', function () { j(addInput).val(++n); j("#field_qb04u").trigger("change"); }) j(this).prev("span").on('click', function () { //If n is bigger or equal to 1 subtract 1 from n if (n >= 1) { j(addInput).val(--n); j("#field_qb04u").trigger("change"); } else { //Otherwise do nothing } }); }); </script>
Andres Garcia answered 1 year ago
Thats perfect Thank you! As far as having the option to Edit from the front-endm What would I need to change for the code to "read" if there is anything in the fieldbox (as I read it in my limited capacity, the variable sets to 0. So if an entry is being Updated, it'll revert that to 0
Rob LeVineRob LeVine replied 1 year ago

I suggest removing the j(addInput).val(n); line and then setting the "Default Value" of field to 0 in the field settings.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right