Set a default choice for single-select

Have a play around with this; I think I understood your desired logic, but hopefully it'll be obvious how to tweak if not:


I also took the liberty to making some of the questions mandatory, so that a8 and a9 only appear after their requisite questions have been answered. Again, once the required questions are answered, a8 and a9 will appear, prefilled. Although you can then manually change/override either computed response, if you go back and change the earlier responses it will not re-update a8 or a9; that's a fundamental limitation of using once()

Thanks but there is an error that popup (cast problem) and A8 is not working for a7sum is no and in the same manner for A7b yes and a7sum no A9 is not working.

K. Yes, I've also been able to reproduce the problem when running on Collect [sorry for the delay, I had to get my Android dev environment reinstalled after Mac OS X upgrade]. I'm not sure yet why javaRosa is complaining, whereas both Validate and Enketo are fine, but I'll try to debug and post back when I have more.

Interesting... so the problem appears to be due to Collect's javaRosa (the piece of code that executes these calculation and relevant expressions) not liking the fact the operand to once() calculation is a numeric function, whereas the target control (select_one) is strictly speaking a string


I think this is probably a bug (@LN ?) because XPath should automatically type cast subexpressions to their desired type(s) as needed. I've worked around this by explicitly forcing the once() operand to a string, using the XPath string() function. Specifically


I've tested the new form and it now runs under Collect OK, so please give it a try and tweak as needed. Sorry for the original form misbehaving.

selectdefault_sample2.xls (22 KB)

The cast problem is solved but the output of A8(Yes) and A9(No) is the same whatever my selection in A7b and A7(SUMMARY) is. I think we need to have a condition statement.

As I said, I had to make some assumptions when interpreting what your desired logic is... When in doubt, I suggest just drawing a truth table, showing all possible permutations of your inputs - a7a, a7b, a7sum - and the desired values of your outputs - a8, a9 - in each case. That unambiguously defines each condition, which will drive what your logical expressions must be.

FYI, since your a8 & a9 results are either Yes(1) or No (0), this can be accomplished with either an if() function, or just simply a boolean expression (true->1, false->0), as I have done.

In our case a8 should be yes if if "a7 is yes or uncertain otherwise the value of a8 should be No. In the same manner a9 will be yes if a7b is yes and a7sum is no otherwise it will be No.And this the logic in my case, if i understood your point.

Can you please re-check your form - in your original above ${a7a} is Yes or No only; it is only ${a7sum} that is Yes/No/Uncertain

This is how the questions are presented:

Code Yes to mean select option Yes