Set a default choice for single-select

Hi,

I'm using the xlsform system to write an ODK survey, and am struggling to
work out how to do the following - any help would be very gratefully
received.

I have two single-select questions using the same choices list. I am
trying to make it the case that the second question will default to the
choice selected for the first question.

For example, if they select 'kilos' for the first question from a list of
possible units of measurement, then the second question will also default
to 'kilos'. But if they select 'grams', the second question will default to
'grams' instead.

Has anyone got a suggestion at what to put in the 'default' column to make
this work?

Many thanks

TLG

As far as I know, this is not possible with ODK Collect. If anyone knows
how to do this, please respond to the list, and I will add it to the
documentation.

··· On Thu, Sep 26, 2013 at 3:11 AM, TLG wrote:

Hi,

I'm using the xlsform system to write an ODK survey, and am struggling to
work out how to do the following - any help would be very gratefully
received.

I have two single-select questions using the same choices list. I am
trying to make it the case that the second question will default to the
choice selected for the first question.

For example, if they select 'kilos' for the first question from a list of
possible units of measurement, then the second question will also default
to 'kilos'. But if they select 'grams', the second question will default to
'grams' instead.

Has anyone got a suggestion at what to put in the 'default' column to make
this work?

Many thanks

TLG

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

I know this is an old thread, however still relevent as the issue remain the same.

The root of the problem is, I think, in Java Rosa itself: the default value inside the XML is set in

Desired_default_value .

Whatever we do, this default value is NOT in a part of the form that is to be dynamically evaluated, therefore any sort of:

${variable_to_use_as_default}

will be seen as just text, not an expression to be evaluated. In order for that to work, we would need to have the default being set in binding, so expressions can be resolved, not directly inside the tags.

Since the Xforms is just based, & converts to, whatever the XML does, then of course in Xforms this won't work either.

There definitely are times when it would be desirable to have a default to be dynamically set, that being said... I guess it's always possible to have it display as a note, but sometimes people don't pay attention after they've been using the form for a while....

Franck

Mitch,

This is as close as I could get. It doesn't really do what is needed,
but the technique might be useful for others....

Attached is a form with two selects. Whatever you pick for the first
select will also be the default value for the second select. The catch
here is that the two selects will always be linked. That is, while you
can change the value of the second select, when you save the form,
it'll write over that choice with the value of the first select.

Personally, I think it's a lot cleaner if the form has the user choose
one unit for the entire form, or have them choose a unit for each
measurement.

Yaw

Select-Test.xml (1.45 KB)

··· -- Need ODK services? http://nafundi.com provides form design, professional support, custom reporting, and software development for ODK.

On Thu, Sep 26, 2013 at 9:17 AM, Mitch Sundt mitchellsundt@gmail.com wrote:

As far as I know, this is not possible with ODK Collect. If anyone knows how
to do this, please respond to the list, and I will add it to the
documentation.

On Thu, Sep 26, 2013 at 3:11 AM, TLG theagoodsell@gmail.com wrote:

Hi,

I'm using the xlsform system to write an ODK survey, and am struggling to
work out how to do the following - any help would be very gratefully
received.

I have two single-select questions using the same choices list. I am
trying to make it the case that the second question will default to the
choice selected for the first question.

For example, if they select 'kilos' for the first question from a list of
possible units of measurement, then the second question will also default to
'kilos'. But if they select 'grams', the second question will default to
'grams' instead.

Has anyone got a suggestion at what to put in the 'default' column to make
this work?

Many thanks

TLG

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Franck,

Agreed that it'd be valuable to have, but only so many dev cycles,
especially on Javarosa. Code contributions are welcome.

Yaw

··· -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

On Thu, Aug 13, 2015 at 8:30 AM, francisvachon.it@gmail.com wrote:

I know this is an old thread, however still relevent as the issue remain the same.

The root of the problem is, I think, in Java Rosa itself: the default value inside the XML is set in

Desired_default_value .

Whatever we do, this default value is NOT in a part of the form that is to be dynamically evaluated, therefore any sort of:

${variable_to_use_as_default}

will be seen as just text, not an expression to be evaluated. In order for that to work, we would need to have the default being set in binding, so expressions can be resolved, not directly inside the tags.

Since the Xforms is just based, & converts to, whatever the XML does, then of course in Xforms this won't work either.

There definitely are times when it would be desirable to have a default to be dynamically set, that being said... I guess it's always possible to have it display as a note, but sometimes people don't pay attention after they've been using the form for a while....

Franck

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups "ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Just providing some feedback on this topic: Yaw's constraint method for
setting default values based on a previous response appears to work fine,
even with select multi type questions (thanks for the tip, Yaw). There are,
however, a couple of caveats: 1) this doesn't appear to work if you are
using XLSForm and entering ${some_previous_question} in the constraint
column... not sure why though, the syntax seems to be correct in the output
XML file; and 2) this doesn't appear to work in Enketo.

Cheers,
-Ed

··· On Thursday, September 26, 2013 7:35:09 PM UTC-5, Yaw Anokwa wrote: > > Mitch, > > This is as close as I could get. It doesn't really do what is needed, > but the technique might be useful for others.... > > Attached is a form with two selects. Whatever you pick for the first > select will also be the default value for the second select. The catch > here is that the two selects will always be linked. That is, while you > can change the value of the second select, when you save the form, > it'll write over that choice with the value of the first select. > > Personally, I think it's a lot cleaner if the form has the user choose > one unit for the entire form, or have them choose a unit for each > measurement. > > Yaw > -- > Need ODK services? http://nafundi.com provides form design, > professional support, custom reporting, and software development for > ODK. > > On Thu, Sep 26, 2013 at 9:17 AM, Mitch Sundt <mitche...@gmail.com> wrote: > > As far as I know, this is not possible with ODK Collect. If anyone knows > how > > to do this, please respond to the list, and I will add it to the > > documentation. > > > > > > On Thu, Sep 26, 2013 at 3:11 AM, TLG <theago...@gmail.com > wrote: > >> > >> Hi, > >> > >> I'm using the xlsform system to write an ODK survey, and am struggling > to > >> work out how to do the following - any help would be very gratefully > >> received. > >> > >> I have two single-select questions using the same choices list. I am > >> trying to make it the case that the second question will default to the > >> choice selected for the first question. > >> > >> For example, if they select 'kilos' for the first question from a list > of > >> possible units of measurement, then the second question will also > default to > >> 'kilos'. But if they select 'grams', the second question will default > to > >> 'grams' instead. > >> > >> > >> Has anyone got a suggestion at what to put in the 'default' column to > make > >> this work? > >> > >> > >> > >> Many thanks > >> > >> > >> TLG > >> > >> -- > >> -- > >> Post: opend...@googlegroups.com > >> Unsubscribe: opendatakit...@googlegroups.com > >> Options: http://groups.google.com/group/opendatakit?hl=en > >> > >> --- > >> You received this message because you are subscribed to the Google > Groups > >> "ODK Community" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an > >> email to opendatakit...@googlegroups.com . > >> For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > > > > -- > > Mitch Sundt > > Software Engineer > > University of Washington > > mitche...@gmail.com > > > > -- > > -- > > Post: opend...@googlegroups.com > > Unsubscribe: opendatakit...@googlegroups.com > > Options: http://groups.google.com/group/opendatakit?hl=en > > > > --- > > You received this message because you are subscribed to the Google > Groups > > "ODK Community" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to opendatakit...@googlegroups.com . > > For more options, visit https://groups.google.com/groups/opt_out. >

Just to catch up on this, so it's still not possible to add a default value to single-select widgets based on previous answers?

I tried something rather simple like but it wouldn't work.

if(/data/is_boss=1,/data/respondent_sex)

If the respondent himself / herself is the boss of a company (is_boss) then the previously selected gender (respondent_sex) is the default value for the gender of the boss (boss_sex).

example.xls (96 KB)
Try this may be helpful for you

@mpds Collect does not support dynamic defaults, but we've documented a workaround using calculates at https://docs.opendatakit.org/form-logic/#setting-default-responses.

In your specific example, instead of attempting to pre-fill boss_sex with a default respondent_sex when is_boss is true, why don't you simply hide showing the boss_sex select question in this case, because its redundant - you already know the answer - and instead compute the answer with something like:

boss-sex-select: ... relevant="/data/is_boss != '1'), required="true()"

boss_sex: calculate="if(/data/is_boss = '1', /data/respondent_sex, /data/boss-sex-select)"

Thank you @yanokwa ! Will have a look at this.

Hi,
Is there any latest update on auto-select single select responses specially using xlsform.
Thanks

Have a look at this:

selectdefault.xls (26.5 KB)

It contains two select_one questions, where the second select_one is preloaded with the default response from the first.

Thank you @Xiphware for your prompt response.But while changing the first choice during edit it will not change the second list, it remain with the first selection. Any fix?
Thanks

Correct. The second select can only be ‘initialized’ once by this means, so subsequently changing the first to a different value won’t do anything.

You might want to rethink your form logic, bearing in mind that, in reality, there isn’t really a specific ‘order’ to questions... So, for example, if I set Q1, then explicitly changed the selected default in Q2 to something else, then went back and changed Q1, what would be your expected result?

Thanks Xiphware, I am checking all the possibilities.I think there might be a possibility in my case and let me see.

Hi Xiphware,
I have tried to apply your example to my case but the answer for the second gets selected even before my selection and that is also the wrong one.I think that could be due to the if condition.Is there any way out?. Attached the scenario i am trying.selectdefault_ex.xls (26.5 KB)
Thanks

Your change wont work because the calculation

${val} = if((${a}='1' and ${b}='1'),'1','0')

will always produce a non-null result, which means the pre-load calculation on your select_one, namely

${testme} = once(${val})

will always have a value - including when you first open the form - which is why it will immediately show 'No' even before you've answered question A.

Could you perhaps try to describe the specific workflow you are trying to accomplish, and I can have a go at seeing how or if it might be possible?

  • Gareth
1 Like

Thank you Xiphaware. As you have seen in the example, I want the final questions to be filled automatically based on the previous response. In the attached file I want a8 and a9 automatically to be filled based on the responses on a7a, a7b and a7sum.selectdefault_sample.xls (29 KB)

Xiphaware. Any workaround on this?