Calculating totals from Repeating section only works with multiple items?


Badge +8

I've got a repeating section, and a calculated value below the repeating section that calculates one of the fields in the repeating section. It works fine, but ONLY if there's more than one entry in the repeating section.

In the screenshots below, the first one shows if I only have one entry. Notice no calculation.

The second one shows if I add a second entry. Now it adds them.

The formula I'm using is "sum(fieldname)". Not much to it. 


17 replies

Userlevel 5
Badge +14

it should work for single repeater row as well...

can you try to put calculation with formula just "fieldname" below the repeater?

how does it evaluated when you have there single and more rows?

Badge +8

I now have a CV that only has "fieldname" in the formula. When adding one item, it shows this:

When adding a second item, it shows this:

When removing an item, it shows this:

Also, I am not able to delete a row from the repeater if it is the only row. Meaning, if I add two rows one identified as A and one as B, and I delete EITHER A or B, the remaining row cannot be removed(by clicking the X button next to the repeater row)

Badge +8

Another interesting thing. It seems if I add a row with a 0 in it, it will calculate the totals correctly.

It just seems like it won't process anything until it has two numbers to add together.

Userlevel 5
Badge +14

Is the field inside of the Repeating Section (Debt Amount) a field that is pulling data asynchronously or something other than a Single Line Text Field? 


Badge +8

The field Debt Amount, above the repeating section is a calculation of two other fields. INSIDE the repeating section, it's just a text field that is input with whatever data is in the CV field.

Userlevel 5
Badge +14

how do you populate value in first row?

it looks like it gets populated after calculation is evaluated and the way that doesn't invoke recalculation

Can you try with just single row in repeater to change  the value (and change focus out of the control)? Does it recalculate?

Userlevel 5
Badge +14

Can you please include a better screenshot of your fields / form, and provide names or labels so that the logic of what is happening can be better understood? 

It's incredibly difficult to evaluate what might be happening with the information provided... 

Badge +8

I'm using JS to take the data from this row and put it into the repeating section. Then I have a CV control below the repeating section trying to get the sum of Medicare Bad Debt Amount. It does so successfully but only AFTER there are two values to get the sum from. It would seem as though it's having trouble getting the sum of one number. In my mind, I would think getting to sum of one number would be the same as getting the sum of that number + 0. It seems like it's stuck waiting on a second number to add to though.

Userlevel 5
Badge +14

If I read correctly, you're pushing data from outside of the Repeating Section into a field (just the first row? new rows?) inside of the Repeating Section? 

I still can't really tell which fields up there belong to a repeating section vs. a row of data, but if I had to take a stab at it (and knowing that you're pushing data using JS), I'd guess that you might be able to fix it by triggering the "change" event on the target control that you're pushing data into initially. 

repeatingSectionControl.val(outerControl.val()).trigger("change");

Again. Without seeing your code or a more explicitly marked up picture, I don't know if this will work, but it's worth a shot to check. 

Userlevel 5
Badge +14

 bingo! JS is the reason, it doesn't fire any events

When you copy value into first (existing) row recalculation isn't invoked.

júst adding a row to repeater causes recalculation.

call focusout() function on the control where you copy value to to

 invoke dependent recalculations

Badge +8

Everything in the top row goes to the field directly below it in the repeating section. The only one that is a calculation is the Bad Debt Amount which is calculated based off the two fields before it(you can see an example of it in the second row of the repeater).

The JS checks for an empty row inside repeater, if row is empty, push data from top row into repeaters empty row. If not empty, create new empty row, then push data down into the newly created row. Finishes by clearing out the data in the top row(outside the repeater).

Badge +8

Marian, 

I'm not the best with JS. You say to call the focusout() function. Can you explain that a little bit more in-depth? 

Userlevel 5
Badge +14

Very... interesting. 

I realize that this is incredibly off topic, but is there any particular reason as to why you don't just allow a user to create / add rows naturally? 

Can you share your code that you're using to populate that new row? (I see that you commented below asking for some JS help). 


Userlevel 5
Badge +14

just like you set value of the control...

I assume you have a call in your code like:  <control>.val(NewValue);

so just add:  <control>.focusout();

Badge +8

Ah, I see now. The problem here is the user isn't going to actually click in that field. We're inputting text into that field from outside the repeater so I'm not sure how to force an update with focusout if they don't actually click inside that field. 

Userlevel 5
Badge +14

that doesn't matter. focus need not in fact be inside control.

important it just to fire event.

Badge +8

Thanks so much happy.png

That worked.

Reply