Once() function evaluated on first character typed in field list in Collect 1.22


Since i made a new update of the odk collect from ODK Collect v1.21.2 to ODK Collect v1.22.4 i got in my form miscalculations and before it was never bad calculated.
please check this xls. I m saying it again it was working good untill i updated the Odk collect.
When i take out the "once" function from my calculation it's working well,but i need that the calculation happens only once.
Test.xls (40.5 KB)

For me when the value is entered in my field "calculate_batch_quantity" it take only the first digit and not the whole number entered (ex 100 it take only the 1) so there is a bad focus on the field it monitor the change but sent the first digit to my calculation that is a "once" function and as it was before the full number was sent to my calculation before.

has any one this same issue with "once" function?


Hi @aydink
welcome to the forum! Please introduce yourself here!

it's related to this feature https://github.com/opendatakit/collect/pull/3023
in your case, the solution would be to remove the first group which contains just one question or at least the field-list appearance.

but I can imagine worse cases when once is used with the field-list appearance, so @LN what do you think?

1 Like

I agree with @Grzesiek2010 -- you can remove field-list from your group appearance or the entire group and that should get the behavior you want without changing anything about how the form is filled out.

Understanding your form design might give us some other ideas, though. Why did you put the first question in a group? Can you tell me more about why you want the calculations to run once? That means that if you change the scaling factor, the recipe won't scale again.

It's true that expressions with once that wrap a value in a field-list will now always capture the first character only. I don't think that's a huge limitation and it feels worth it to have live updates while typing but I'll keep thinking through it. At the very least this should be documented.

Yeah, I agree with you.

1 Like

Hi @Grzesiek2010 , @LN

Thank you for your reply, @Grzesiek2010 i will do my introduction later, if i may?:slight_smile:
The test.xls is not really my entier form that you know already :slight_smile:

In my original form i placed in group and apparence as a field-list since the begining to ask the person that fill the form two question : one to "select_one" the recipe name and after to fill the quantity he's using from one batch to calculate the amount of ingredients in the next group,
Why only "once" because i wanted that the form to be more flexible so if they are doing tests with other value than the value already set with a csv pulldata :). After i calculate all the ingredients outside odk for tracabilities purpose.

And today with some other test with my original form i found out that if i set first the quantity field and after only to select the recipe name it's working the calculation here the files: csv for the pulldata's and the xls with the two questions
prod.csv (215 Bytes) PRO.xls (40 KB)

so in big if i select the recipe first it's not calculated correctly and if i enter the quantity first then it's behaving like before :slight_smile: strange i found another way to get rid of this miscalculation.

Thank you i will continue with first filling the quantity and then select my recipe :wink:

That makes a lot more sense!

What the once() function does is to perform the calculation only if the calculate's value is not blank. The change in behavior that you're observing is because starting in Collect v1.22, calculations within a screen are performed in real time. With text/numeric fields, updates happen as new characters are entered. When you picked your recipe first, there was enough information to perform the calculation as soon as one character was typed and the resulting field was populated with the answer. Since it was no longer blank, it didn't get updated when an additional character was typed.

Switching the order of your questions is a great approach -- when you set the multiplier, there isn't yet enough information to perform the calculations so the calculate fields remain blank. Then when you pick the recipe, the calculations are performed. Since the calculate fields are no longer blank, the calculations won't occur again.

I think there will be easy solutions like this one to issues introduced by updates on new character. Let's keep an eye on it, though.

Bonne cuisine. :cake:

@LN Thanks for this explanation and I m lucky that we could solve it this easy way hehe :slight_smile:

I keep an eye on the next changes in the future versions :wink: