Find out String Widget's XFORM XML Name in ODK Collect Source

Hi ODK Devs,

I was wondering if there is some way we can find out the name of the string
field (better yet any kind of field) we set in XFORM XML (e.g.
) inside ODK Collect -> Widgets -> StringWidget, I am trying to achieve
something similar:

IF (fieldName == 'startTime') {

PERFORM_ACTION_A();
PERFORM_ACTION_B();
....
Display some toast messages ... 

}

Regards,
Ayub

From a software design standpoint, you really should not be doing this.
It makes your changes very brittle and will create an upgrade hassle for
anyone who inherits the maintenance of this code and the associated forms.

Have you considered moving this functionality into an external app? See
http://opendatakit.org/help/form-design/external-apps/

There are new features in 1.4.3 that allow you to pass arbitrary fields
into that app and also set multiple values upon return. These are done
using the appearance attribute. You could then define in the form an:

appearance="ex:my.intent(theFieldName='fieldname')" and have the app that
handles 'my.intent' look for that additional argument
(extras.getString('theFieldName')) to do whatever special handling you want.

This has the advantage of not requiring any changes to ODK Collect, so you
can freely update to the newest versions of ODK Collect as they get updated.

Otherwise, if you are committed to hacking the code, from the
FormEntryPrompt, you should be able to call getFormElement(), cast that to
a TreeElement, and then call getName()

··· On Wed, May 14, 2014 at 2:58 AM, Ayub wrote:

Hi ODK Devs,

I was wondering if there is some way we can find out the name of the
string field (better yet any kind of field) we set in XFORM XML (e.g.
) inside ODK Collect -> Widgets -> StringWidget, I am trying
to achieve something similar:

IF (fieldName == 'startTime') {

PERFORM_ACTION_A();
PERFORM_ACTION_B();
....
Display some toast messages ...

}

Regards,
Ayub

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

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

Thanks for the detailed Answer Mitch,

I have yet to try the new ODK Collect, if multiple values can be returned
from an external app, that would be a something i long awaited.

I understand that it wouldn't be the best approach but wanted to try it
out, i tried following code in String Widget both Public/Private
constructors and i am getting same Cast Errors inside a dialog, i.e.
QuestionDef cannot be cast to JavaRosa TreeElement ... (at runtime).

Code:

public StringWidget(Context context, FormEntryPrompt prompt) {

    TreeElement Te = (TreeElement) prompt.getFormElement();
    Toast.makeText(context, Te.getName().toString(), 

Toast.LENGTH_LONG).show();

....

}

Regards,
Ayub

Hmm. Looked into this further. It does not appear to be possible without
modifying the JR library.

··· On Wed, May 14, 2014 at 10:56 PM, Ayub wrote:

Thanks for the detailed Answer Mitch,

I have yet to try the new ODK Collect, if multiple values can be returned
from an external app, that would be a something i long awaited.

I understand that it wouldn't be the best approach but wanted to try it
out, i tried following code in String Widget both Public/Private
constructors and i am getting same Cast Errors inside a dialog, i.e.
QuestionDef cannot be cast to JavaRosa TreeElement ... (at runtime).

Code:

public StringWidget(Context context, FormEntryPrompt prompt) {

    TreeElement Te = (TreeElement) prompt.getFormElement();
    Toast.makeText(context, Te.getName().toString(),

Toast.LENGTH_LONG).show();

....

}

Regards,
Ayub

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

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

Alright, thanks for the help.

Ayub , did you found the solution for your Question yet? I also have the same problem like you.

Not yet Yin, since Mitch told that JR needed modifications for this to work
and i have no expertise in that. If you ever find the solution to it,
please let me know :slight_smile:

Regards,
Ayub

··· On Fri, Aug 1, 2014 at 1:02 PM, wrote:

Ayub , did you found the solution for your Question yet? I also have the
same problem like you.

--
You received this message because you are subscribed to a topic in the
Google Groups "ODK Developers" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/opendatakit-developers/Ps575c9MF9I/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.