Copy a field into another

Hi, we are using the calculate to preload a value in an input field that could be modified later on from the user.

the problem is that whatever the user will put in the question_2 input fields will be overwritten from odk with the initial calculate...

we tried to put an if statement to check that if question_2 has already a value don't put the question_1 value...but it is correctly going in dependency cycle.

which is the correct way to preload a value in a input field without loose the modified value when the user put it?

Thank you very much
Angelo

Angelo, I don't think this is possible. Your options are:

  • Set a static default value by putting the value in the default column XLSForm.
  • Reference the value of q1 in the label of q2 and instruct the user to enter that.

I think this might be a useful thing to add to ODK so I'm moving this thread to Features. @martijnr is this something that we could enable in the spec?

I wonder if using once() would meet your requirements. The name of this function is not very descriptive as it works like if_empty() and therefore wouldn't override a user-entered value, unless the user-entered value is empty. We should perhaps consider adding an alias for once().

Thanks every body, once works perfectly, i didn't know about that function, probably because of the reason @martijnr said... anyway.. another great work from this community.. thank YOU so much guys!!

I've added an issue at https://github.com/opendatakit/xforms-spec/issues/130 to discuss the alias. Seems like a reasonable idea.

1 Like