Hi All
I would like to customise the text that appears when a required field
is not completed. At the moment, you get the standard "Sorry, this
response is required!" - I would prefer a field-specific message. I'm
not sure if there is another way to achieve this, but I changed the
createConstraintToast method in activities/FormEntryActivity.java to
look as follows:
private void createConstraintToast(String constraintText, int
saveStatus) {
switch (saveStatus) {
case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
if (constraintText == null) {
constraintText =
getString(R.string.invalid_answer_error);
}
break;
case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
if (constraintText == null) {
constraintText =
getString(R.string.required_answer_error);
}
break;
}
showCustomToast(constraintText);
mBeenSwiped = false;
}
Now instead of the default text, the constraintMsg property is used if
it is available.
Another question - I don't see any way to translate this text based on
the currently selected language. Is this possible?
Thanks
Adi
Forgot to mention, due to the way getConstraint works - you still need
to add in a constraint.
e.g. for a string type I have been using constraint=". != ''"
the constraint has to be valid - so for a numeric type, I have been
using constraint=". != -999" (somewhat hackish i know)
I'm not sure what to do for a geopoint type - any suggestions?
Adi
···
On Oct 2, 7:59 am, Adi Eyal wrote:
> Hi All
>
> I would like to customise the text that appears when a required field
> is not completed. At the moment, you get the standard "Sorry, this
> response is required!" - I would prefer a field-specific message. I'm
> not sure if there is another way to achieve this, but I changed the
> createConstraintToast method in activities/FormEntryActivity.java to
> look as follows:
>
> private void createConstraintToast(String constraintText, int
> saveStatus) {
> switch (saveStatus) {
> case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
> if (constraintText == null) {
> constraintText =
> getString(R.string.invalid_answer_error);
> }
> break;
> case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
> if (constraintText == null) {
> constraintText =
> getString(R.string.required_answer_error);
> }
> break;
> }
>
> showCustomToast(constraintText);
> mBeenSwiped = false;
> }
>
> Now instead of the default text, the constraintMsg property is used if
> it is available.
>
> Another question - I don't see any way to translate this text based on
> the currently selected language. Is this possible?
>
> Thanks
> Adi
Adi,
I see you have a couple skip logic related questions; you might find it
easier to use a GUI for writing your skip logic. Try this:
http://formbuilder.kobotoolbox.org/KoBoFormDesigner.html
There is a Getting Started tutorial here:
And some specific help about skip logic here:
Just a tip, you are clearly already working on your survey, you don't have
to start over, just import it into the form designer
Main Menu >> Open From File
Let me know if you have any trouble.
☞§※☼:airplane:
~Neil
···
On Sun, Oct 2, 2011 at 1:59 AM, Adi Eyal wrote:
Hi All
I would like to customise the text that appears when a required field
is not completed. At the moment, you get the standard "Sorry, this
response is required!" - I would prefer a field-specific message. I'm
not sure if there is another way to achieve this, but I changed the
createConstraintToast method in activities/FormEntryActivity.java to
look as follows:
private void createConstraintToast(String constraintText, int
saveStatus) {
switch (saveStatus) {
case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
if (constraintText == null) {
constraintText =
getString(R.string.invalid_answer_error);
}
break;
case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
if (constraintText == null) {
constraintText =
getString(R.string.required_answer_error);
}
break;
}
showCustomToast(constraintText);
mBeenSwiped = false;
}
Now instead of the default text, the constraintMsg property is used if
it is available.
Another question - I don't see any way to translate this text based on
the currently selected language. Is this possible?
Thanks
Adi
you can also make a question not required, but then do a constraint
regex that checks for blank responses. that'll get it to display the
constraint message without any source code changes.
i don't think constraint messages are localizable, but you can submit
a patch to javarosa-core that enables that. i've filed a bug
http://code.google.com/p/opendatakit/issues/detail?id=352 as a
reminder. feel free to submit the patch there.
···
On Sun, Oct 2, 2011 at 02:25, Adi Eyal wrote:
> Forgot to mention, due to the way getConstraint works - you still need
> to add in a constraint.
>
> e.g. for a string type I have been using constraint=". != ''"
>
> the constraint has to be valid - so for a numeric type, I have been
> using constraint=". != -999" (somewhat hackish i know)
>
> I'm not sure what to do for a geopoint type - any suggestions?
>
> Adi
>
> On Oct 2, 7:59 am, Adi Eyal wrote:
>> Hi All
>>
>> I would like to customise the text that appears when a required field
>> is not completed. At the moment, you get the standard "Sorry, this
>> response is required!" - I would prefer a field-specific message. I'm
>> not sure if there is another way to achieve this, but I changed the
>> createConstraintToast method in activities/FormEntryActivity.java to
>> look as follows:
>>
>> private void createConstraintToast(String constraintText, int
>> saveStatus) {
>> switch (saveStatus) {
>> case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
>> if (constraintText == null) {
>> constraintText =
>> getString(R.string.invalid_answer_error);
>> }
>> break;
>> case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
>> if (constraintText == null) {
>> constraintText =
>> getString(R.string.required_answer_error);
>> }
>> break;
>> }
>>
>> showCustomToast(constraintText);
>> mBeenSwiped = false;
>> }
>>
>> Now instead of the default text, the constraintMsg property is used if
>> it is available.
>>
>> Another question - I don't see any way to translate this text based on
>> the currently selected language. Is this possible?
>>
>> Thanks
>> Adi
>
I tried that and it didn't work which is why I went for the above
approach. I guess I got so caught up trying to get my forms working
that I didn't think to ask this simple question. Why doesn't my
constraint below work?
the full test form is below
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://
www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://
openrosa.org/javarosa">
<h:head>
<h:title>test</h:title>
Test
</h:head>
<h:body>
</h:body>
</h:html>
···
On Oct 4, 3:22 am, Yaw Anokwa wrote:
> you can also make a question not required, but then do a constraint
> regex that checks for blank responses. that'll get it to display the
> constraint message without any source code changes.
> i don't think constraint messages are localizable, but you can submit
> a patch to javarosa-core that enables that. i've filed a bughttp://code.google.com/p/opendatakit/issues/detail?id=352as a
> reminder. feel free to submit the patch there.
>
>
>
>
>
>
>
> On Sun, Oct 2, 2011 at 02:25, Adi Eyal wrote:
> > Forgot to mention, due to the way getConstraint works - you still need
> > to add in a constraint.
>
> > e.g. for a string type I have been using constraint=". != ''"
>
> > the constraint has to be valid - so for a numeric type, I have been
> > using constraint=". != -999" (somewhat hackish i know)
>
> > I'm not sure what to do for a geopoint type - any suggestions?
>
> > Adi
>
> > On Oct 2, 7:59 am, Adi Eyal wrote:
> >> Hi All
>
> >> I would like to customise the text that appears when a required field
> >> is not completed. At the moment, you get the standard "Sorry, this
> >> response is required!" - I would prefer a field-specific message. I'm
> >> not sure if there is another way to achieve this, but I changed the
> >> createConstraintToast method in activities/FormEntryActivity.java to
> >> look as follows:
>
> >> private void createConstraintToast(String constraintText, int
> >> saveStatus) {
> >> switch (saveStatus) {
> >> case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
> >> if (constraintText == null) {
> >> constraintText =
> >> getString(R.string.invalid_answer_error);
> >> }
> >> break;
> >> case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
> >> if (constraintText == null) {
> >> constraintText =
> >> getString(R.string.required_answer_error);
> >> }
> >> break;
> >> }
>
> >> showCustomToast(constraintText);
> >> mBeenSwiped = false;
> >> }
>
> >> Now instead of the default text, the constraintMsg property is used if
> >> it is available.
>
> >> Another question - I don't see any way to translate this text based on
> >> the currently selected language. Is this possible?
>
> >> Thanks
> >> Adi
the constraint should be != "", not !="
···
On Tue, Oct 4, 2011 at 22:07, Adi Eyal wrote:
> I tried that and it didn't work which is why I went for the above
> approach. I guess I got so caught up trying to get my forms working
> that I didn't think to ask this simple question. Why doesn't my
> constraint below work?
>
> jr:constraintMsg="This is a required field - please enter"/>
>
> the full test form is below
>
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://
> openrosa.org/javarosa">
>
> test
>
>
>
>
>
>
>
>
>
> Test
>
>
>
>
>
>
> jr:constraintMsg="This is a required field - please enter"/>
>
>
>
>
>
>
>
>
>
>
>
> On Oct 4, 3:22 am, Yaw Anokwa wrote:
>> you can also make a question not required, but then do a constraint
>> regex that checks for blank responses. that'll get it to display the
>> constraint message without any source code changes.
>> i don't think constraint messages are localizable, but you can submit
>> a patch to javarosa-core that enables that. i've filed a bughttp://code.google.com/p/opendatakit/issues/detail?id=352as a
>> reminder. feel free to submit the patch there.
>>
>>
>>
>>
>>
>>
>>
>> On Sun, Oct 2, 2011 at 02:25, Adi Eyal wrote:
>> > Forgot to mention, due to the way getConstraint works - you still need
>> > to add in a constraint.
>>
>> > e.g. for a string type I have been using constraint=". != ''"
>>
>> > the constraint has to be valid - so for a numeric type, I have been
>> > using constraint=". != -999" (somewhat hackish i know)
>>
>> > I'm not sure what to do for a geopoint type - any suggestions?
>>
>> > Adi
>>
>> > On Oct 2, 7:59 am, Adi Eyal wrote:
>> >> Hi All
>>
>> >> I would like to customise the text that appears when a required field
>> >> is not completed. At the moment, you get the standard "Sorry, this
>> >> response is required!" - I would prefer a field-specific message. I'm
>> >> not sure if there is another way to achieve this, but I changed the
>> >> createConstraintToast method in activities/FormEntryActivity.java to
>> >> look as follows:
>>
>> >> private void createConstraintToast(String constraintText, int
>> >> saveStatus) {
>> >> switch (saveStatus) {
>> >> case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
>> >> if (constraintText == null) {
>> >> constraintText =
>> >> getString(R.string.invalid_answer_error);
>> >> }
>> >> break;
>> >> case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
>> >> if (constraintText == null) {
>> >> constraintText =
>> >> getString(R.string.required_answer_error);
>> >> }
>> >> break;
>> >> }
>>
>> >> showCustomToast(constraintText);
>> >> mBeenSwiped = false;
>> >> }
>>
>> >> Now instead of the default text, the constraintMsg property is used if
>> >> it is available.
>>
>> >> Another question - I don't see any way to translate this text based on
>> >> the currently selected language. Is this possible?
>>
>> >> Thanks
>> >> Adi
>