Solution: error message in multiple languages using itext

Just thought I'd share this since I hadn't seen it posted anywhere. I hope
it is clear, but I'm happy to clarify if not.

If you create a constraint and the operator tries to input an answer that
does not obey the constraint, the default eror message in ODK is "Sorry,
this response is invalid." There are many times when you might want to
create a custom error message - for example a message which tells the
person why the response is invalid, or one which appears in the language
the operator is using.

Let's use an example in English and Spanish, where, if someone gives an
answer to question "B8" that does not make sense given the answer to
question "B3", we can return a custom error message in either language
using jr:constraintMsg in the bindings. B3 is an integer. If the choice
for question B8 is '1' then the answer to B3 must be less than 5. If the
choice for B8 is '2', then B3 must be 5 or greater.

You can manually change the error message as follows:

But the above constraint message will appear the same no matter what
language the surveyor is using, which has obvious limitations.

To create a custom error message in multiple languages using itext, use the
following structure:

··· ======= =======

Does not agree with B3

No está de acuerdo con B3

=======

Only the necessary code is shown above, but of course all of the normal
parts of an ODK xml file are needed.

The key here is to create text in all languages using itext, then refer to
that itext using the command jr:constraintMsg="jr:itext("

Substitute /data/B8:errorMsg for whatever question you are working on.
"errorMsg" is my own name, you can change it if you like.

great tip, luke. i've added it to
http://opendatakit.org/help/form-design/binding/

··· On Wed, Dec 14, 2011 at 09:35, Luke wrote: > Just thought I'd share this since I hadn't seen it posted anywhere. I hope > it is clear, but I'm happy to clarify if not. > > If you create a constraint and the operator tries to input an answer that > does not obey the constraint, the default eror message in ODK is "Sorry, > this response is invalid." There are many times when you might want to > create a custom error message - for example a message which tells the person > why the response is invalid, or one which appears in the language the > operator is using. > > Let's use an example in English and Spanish, where, if someone gives an > answer to question "B8" that does not make sense given the answer to > question "B3", we can return a custom error message in either language using > jr:constraintMsg in the bindings. B3 is an integer. If the choice for > question B8 is '1' then the answer to B3 must be less than 5. If the choice > for B8 is '2', then B3 must be 5 or greater. > > You can manually change the error message as follows: > > > jr:constraintMsg="Does not agree with B3"/> > > > But the above constraint message will appear the same no matter what > language the surveyor is using, which has obvious limitations. > > To create a custom error message in multiple languages using itext, use the > following structure: > > ======= > ======= > > > > > > > > > > > > Does not agree with B3 > > > > > > > > > > > > > > > > No está de acuerdo con B3 > > > > > > > > > > jr:constraintMsg="jr:itext('/data/B8:errorMsg')"/> > > ======= > ======= > > Only the necessary code is shown above, but of course all of the normal > parts of an ODK xml file are needed. > > The key here is to create text in all languages using itext, then refer to > that itext using the command jr:constraintMsg="jr:itext(" > > Substitute /data/B8:errorMsg for whatever question you are working on. > "errorMsg" is my own name, you can change it if you like. > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en