Input hidden in xforms

hi,

I have a form with a node like:

and I would like to add a hidden id (called person_id) which is filled
with the current value of "jr:count".

I've seen XForms doesn't support hidden values because "any values in
the instance that haven't been bound to by a control are by definition
not visible to the user".

but I don't see how could I use the jr:count value. I tried by using
the IDREF of the repeat node and calling it from the bindings:

but it didn't work. I tried also some other possibilities, but I'm not
even sure 'calculate' is fully supported by javarosa (it works in some
cases, although in the documentation it's said 'calculate' is not
supported).

Do you have any idea about how to create such 'hidden id' without
having to add an input method? I've seen ODK prints the iteration
number in a 'repeat' loop, but it seems it doesn't use the index
function, but some internal counter.

thanks in advance,

best,

pau.

hi pau,

i understand what you are asking but don't have an immediate response.
i've escalated to some xforms experts and i'll let you know when i
know...

yaw

··· On Tue, Jun 8, 2010 at 02:09, Pau Varela wrote: > hi, > > I have a form with a node like: > > jr:noAddRemove="true()" jr:count="/data/household/adults_missing" > id="person-repeat"> > > and I would like to add a hidden id (called person_id) which is filled > with the current value of "jr:count". > > I've seen XForms doesn't support hidden values because "any values in > the instance that haven't been bound to by a control are by definition > not visible to the user". > > but I don't see how could I use the jr:count value. I tried by using > the IDREF of the repeat node and calling it from the bindings: > > type="int" calculate="index('person-repeat')"/> > > but it didn't work. I tried also some other possibilities, but I'm not > even sure 'calculate' is fully supported by javarosa (it works in some > cases, although in the documentation it's said 'calculate' is not > supported). > > Do you have any idea about how to create such 'hidden id' without > having to add an input method? I've seen ODK prints the iteration > number in a 'repeat' loop, but it seems it doesn't use the index > function, but some internal counter. > > thanks in advance, > > best, > > pau. > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

Pau,

To clarify: Are you trying to access the current index of the repeat node?
IE: Filling out the id field in this sample template?

Clayton 1 Yaw 2

We don't current support the xform function which returns the index of the
current repeat (because the function's contract requires the repeat to have
an XML ID, which is also currently unsupported).

We are going to expand the set of supported XPath expressions in a future
release of our core XForm library, but I'm not sure exactly when that will
be. It would be possible to write in this function into a custom version of
ODK which registered a function handler with the parser as advanced
behavior...

-Clayton

··· On Tue, Jun 8, 2010 at 9:37 AM, Yaw Anokwa wrote:

hi pau,

i understand what you are asking but don't have an immediate response.
i've escalated to some xforms experts and i'll let you know when i
know...

yaw

On Tue, Jun 8, 2010 at 02:09, Pau Varela pau.varela@gmail.com wrote:

hi,

I have a form with a node like:

and I would like to add a hidden id (called person_id) which is filled
with the current value of "jr:count".

I've seen XForms doesn't support hidden values because "any values in
the instance that haven't been bound to by a control are by definition
not visible to the user".

but I don't see how could I use the jr:count value. I tried by using
the IDREF of the repeat node and calling it from the bindings:

but it didn't work. I tried also some other possibilities, but I'm not
even sure 'calculate' is fully supported by javarosa (it works in some
cases, although in the documentation it's said 'calculate' is not
supported).

Do you have any idea about how to create such 'hidden id' without
having to add an input method? I've seen ODK prints the iteration
number in a 'repeat' loop, but it seems it doesn't use the index
function, but some internal counter.

thanks in advance,

best,

pau.

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

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

hi Clayton and Yaw,

thanks for your replies. yes, access to the current index of the
repeat node is exactly what I would like to do.

My impression was it wasn't supported, but I wanted to verify it.
unfortunately, it seems I was right :wink:

I only have been working with XForms for a couple of months and
looking at the 'pure' XForms documentation, it seems that using the
node's IDREF (I understand it's the XML ID you mention) together with
the index() funtion is possible to access to this value. But after
trying it and reading javarosa documentation, I wasn't able to do it
and that's why I sent here my question. Now at least I know the
reason...

The project I'm working for (eMOCHA) is using already a modified
version of ODK.. when you say "It would be possible to write in this
function into a custom version of ODK which registered a function
handler with the parser as advanced behavior...", how do I register a
function handler? could you please give me some other hint or some
class names so I can take a look at the code?

thanks again,

pau.

··· 2010/6/9 Clayton Sims : > Pau, > To clarify: Are you trying to access the current index of the repeat node? > IE: Filling out the id field in this sample template? > > > Clayton > 1 > > > Yaw > 2 > > > We don't current support the xform function which returns the index of the > current repeat (because the function's contract requires the repeat to have > an XML ID, which is also currently unsupported). > We are going to expand the set of supported XPath expressions in a future > release of our core XForm library, but I'm not sure exactly when that will > be. It would be possible to write in this function into a custom version of > ODK which registered a function handler with the parser as advanced > behavior... > -Clayton > On Tue, Jun 8, 2010 at 9:37 AM, Yaw Anokwa wrote: >> >> hi pau, >> >> i understand what you are asking but don't have an immediate response. >> i've escalated to some xforms experts and i'll let you know when i >> know... >> >> yaw >> >> On Tue, Jun 8, 2010 at 02:09, Pau Varela wrote: >> > hi, >> > >> > I have a form with a node like: >> > >> > > > jr:noAddRemove="true()" jr:count="/data/household/adults_missing" >> > id="person-repeat"> >> > >> > and I would like to add a hidden id (called person_id) which is filled >> > with the current value of "jr:count". >> > >> > I've seen XForms doesn't support hidden values because "any values in >> > the instance that haven't been bound to by a control are by definition >> > not visible to the user". >> > >> > but I don't see how could I use the jr:count value. I tried by using >> > the IDREF of the repeat node and calling it from the bindings: >> > >> > > > type="int" calculate="index('person-repeat')"/> >> > >> > but it didn't work. I tried also some other possibilities, but I'm not >> > even sure 'calculate' is fully supported by javarosa (it works in some >> > cases, although in the documentation it's said 'calculate' is not >> > supported). >> > >> > Do you have any idea about how to create such 'hidden id' without >> > having to add an input method? I've seen ODK prints the iteration >> > number in a 'repeat' loop, but it seems it doesn't use the index >> > function, but some internal counter. >> > >> > thanks in advance, >> > >> > best, >> > >> > pau. >> > >> > -- >> > Post: opendatakit@googlegroups.com >> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> > Options: http://groups.google.com/group/opendatakit?hl=en >> > >> >> -- >> Post: opendatakit@googlegroups.com >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> Options: http://groups.google.com/group/opendatakit?hl=en > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

Pau,

In the code there is a class which is created when a form entry model and
controller is generated called EvaluationContext which maintains the state
necessary to evaluate XPath expressions during form entry. This class allows
you to register IFunctionHandler's which can define new functions to be used
in XPath expressions.

Implementing a function to pull the index of the current repeat would
definitely be tricky, but I believe you could possibly do it with some
assumptions and hacking. You can see the function handling code at

http://www.bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java

You probably want to get an argument as a XPathNodeset or the node itself
and do something like walk up its reference or tree structure until a repeat
is found, then look for its index.

-Clayton

··· On Wed, Jun 9, 2010 at 12:06 PM, Pau Varela wrote:

hi Clayton and Yaw,

thanks for your replies. yes, access to the current index of the
repeat node is exactly what I would like to do.

My impression was it wasn't supported, but I wanted to verify it.
unfortunately, it seems I was right :wink:

I only have been working with XForms for a couple of months and
looking at the 'pure' XForms documentation, it seems that using the
node's IDREF (I understand it's the XML ID you mention) together with
the index() funtion is possible to access to this value. But after
trying it and reading javarosa documentation, I wasn't able to do it
and that's why I sent here my question. Now at least I know the
reason...

The project I'm working for (eMOCHA) is using already a modified
version of ODK.. when you say "It would be possible to write in this
function into a custom version of ODK which registered a function
handler with the parser as advanced behavior...", how do I register a
function handler? could you please give me some other hint or some
class names so I can take a look at the code?

thanks again,

pau.

2010/6/9 Clayton Sims csims@dimagi.com:

Pau,
To clarify: Are you trying to access the current index of the repeat
node?
IE: Filling out the id field in this sample template?


Clayton
1


Yaw
2


We don't current support the xform function which returns the index of
the
current repeat (because the function's contract requires the repeat to
have
an XML ID, which is also currently unsupported).
We are going to expand the set of supported XPath expressions in a future
release of our core XForm library, but I'm not sure exactly when that
will
be. It would be possible to write in this function into a custom version
of
ODK which registered a function handler with the parser as advanced
behavior...
-Clayton
On Tue, Jun 8, 2010 at 9:37 AM, Yaw Anokwa yanokwa@gmail.com wrote:

hi pau,

i understand what you are asking but don't have an immediate response.
i've escalated to some xforms experts and i'll let you know when i
know...

yaw

On Tue, Jun 8, 2010 at 02:09, Pau Varela pau.varela@gmail.com wrote:

hi,

I have a form with a node like:

and I would like to add a hidden id (called person_id) which is filled
with the current value of "jr:count".

I've seen XForms doesn't support hidden values because "any values in
the instance that haven't been bound to by a control are by definition
not visible to the user".

but I don't see how could I use the jr:count value. I tried by using
the IDREF of the repeat node and calling it from the bindings:

but it didn't work. I tried also some other possibilities, but I'm not
even sure 'calculate' is fully supported by javarosa (it works in some
cases, although in the documentation it's said 'calculate' is not
supported).

Do you have any idea about how to create such 'hidden id' without
having to add an input method? I've seen ODK prints the iteration
number in a 'repeat' loop, but it seems it doesn't use the index
function, but some internal counter.

thanks in advance,

best,

pau.

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

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

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

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

hi Clayton,

thanks for the tip. I've been looking at the code and, as you said, it
seems not easy, but possible...

I understand I should define my own IFunctionHandler class, like the
org.odk.collect.android.RegexFunction and let XPathFuncExpr call its
methods when creating/editing the forms.

Since I don't see how to read, in run-time, the index of a repeat node
from its binding, I think I'll go for some dirty solution like storing
temporarily the number of created nodes and check it against the
numbers of node I have to create (the count number), in order to know
the next id. It is not nice, but I guess it will work. Otherwise I
think I should do a lot of hacking in ODK and maybe javarosa..

My last question would be if calling functions from the calculate
attribute is a supported feature. According to the doc
(http://code.javarosa.org/wiki/xform) it's not, but our forms contain
some calls to the "if" function defined in the XPathFuncExpr class
(e.g: calculate="if(/data/scheduled_fu_visit_date > today(), '1',
'0')") and they are working fine.

Anyway, I'll try and see :wink:

thanks again for your help

pau.

··· 2010/6/11 Clayton Sims : > Pau, > In the code there is a class which is created when a form entry model and > controller is generated called EvaluationContext which maintains the state > necessary to evaluate XPath expressions during form entry. This class allows > you to register IFunctionHandler's which can define new functions to be used > in XPath expressions. > Implementing a function to pull the index of the current repeat would > definitely be tricky, but I believe you could possibly do it with some > assumptions and hacking. You can see the function handling code at > http://www.bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java > You probably want to get an argument as a XPathNodeset or the node itself > and do something like walk up its reference or tree structure until a repeat > is found, then look for its index. > -Clayton > On Wed, Jun 9, 2010 at 12:06 PM, Pau Varela wrote: >> >> hi Clayton and Yaw, >> >> thanks for your replies. yes, access to the current index of the >> repeat node is exactly what I would like to do. >> >> My impression was it wasn't supported, but I wanted to verify it. >> unfortunately, it seems I was right ;) >> >> I only have been working with XForms for a couple of months and >> looking at the 'pure' XForms documentation, it seems that using the >> node's IDREF (I understand it's the XML ID you mention) together with >> the index() funtion is possible to access to this value. But after >> trying it and reading javarosa documentation, I wasn't able to do it >> and that's why I sent here my question. Now at least I know the >> reason... >> >> The project I'm working for (eMOCHA) is using already a modified >> version of ODK.. when you say "It would be possible to write in this >> function into a custom version of ODK which registered a function >> handler with the parser as advanced behavior...", how do I register a >> function handler? could you please give me some other hint or some >> class names so I can take a look at the code? >> >> thanks again, >> >> pau. >> >> 2010/6/9 Clayton Sims : >> > Pau, >> > To clarify: Are you trying to access the current index of the repeat >> > node? >> > IE: Filling out the id field in this sample template? >> > >> > >> > Clayton >> > 1 >> > >> > >> > Yaw >> > 2 >> > >> > >> > We don't current support the xform function which returns the index of >> > the >> > current repeat (because the function's contract requires the repeat to >> > have >> > an XML ID, which is also currently unsupported). >> > We are going to expand the set of supported XPath expressions in a >> > future >> > release of our core XForm library, but I'm not sure exactly when that >> > will >> > be. It would be possible to write in this function into a custom version >> > of >> > ODK which registered a function handler with the parser as advanced >> > behavior... >> > -Clayton >> > On Tue, Jun 8, 2010 at 9:37 AM, Yaw Anokwa wrote: >> >> >> >> hi pau, >> >> >> >> i understand what you are asking but don't have an immediate response. >> >> i've escalated to some xforms experts and i'll let you know when i >> >> know... >> >> >> >> yaw >> >> >> >> On Tue, Jun 8, 2010 at 02:09, Pau Varela wrote: >> >> > hi, >> >> > >> >> > I have a form with a node like: >> >> > >> >> > > >> > jr:noAddRemove="true()" jr:count="/data/household/adults_missing" >> >> > id="person-repeat"> >> >> > >> >> > and I would like to add a hidden id (called person_id) which is >> >> > filled >> >> > with the current value of "jr:count". >> >> > >> >> > I've seen XForms doesn't support hidden values because "any values in >> >> > the instance that haven't been bound to by a control are by >> >> > definition >> >> > not visible to the user". >> >> > >> >> > but I don't see how could I use the jr:count value. I tried by using >> >> > the IDREF of the repeat node and calling it from the bindings: >> >> > >> >> > > >> > type="int" calculate="index('person-repeat')"/> >> >> > >> >> > but it didn't work. I tried also some other possibilities, but I'm >> >> > not >> >> > even sure 'calculate' is fully supported by javarosa (it works in >> >> > some >> >> > cases, although in the documentation it's said 'calculate' is not >> >> > supported). >> >> > >> >> > Do you have any idea about how to create such 'hidden id' without >> >> > having to add an input method? I've seen ODK prints the iteration >> >> > number in a 'repeat' loop, but it seems it doesn't use the index >> >> > function, but some internal counter. >> >> > >> >> > thanks in advance, >> >> > >> >> > best, >> >> > >> >> > pau. >> >> > >> >> > -- >> >> > Post: opendatakit@googlegroups.com >> >> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> >> > Options: http://groups.google.com/group/opendatakit?hl=en >> >> > >> >> >> >> -- >> >> Post: opendatakit@googlegroups.com >> >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> >> Options: http://groups.google.com/group/opendatakit?hl=en >> > >> > -- >> > Post: opendatakit@googlegroups.com >> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> > Options: http://groups.google.com/group/opendatakit?hl=en >> > >> >> -- >> Post: opendatakit@googlegroups.com >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> Options: http://groups.google.com/group/opendatakit?hl=en > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

Pau,

Calling functions from calculate is a supported feature, that doc is
slightly out of date, sorry.

Additionally, you should be able to get the index of a repeat node from its
treereference (or the treereference of a parent node which is the repeat).

-Clayton

··· On Mon, Jun 14, 2010 at 7:08 AM, Pau Varela wrote:

hi Clayton,

thanks for the tip. I've been looking at the code and, as you said, it
seems not easy, but possible...

I understand I should define my own IFunctionHandler class, like the
org.odk.collect.android.RegexFunction and let XPathFuncExpr call its
methods when creating/editing the forms.

Since I don't see how to read, in run-time, the index of a repeat node
from its binding, I think I'll go for some dirty solution like storing
temporarily the number of created nodes and check it against the
numbers of node I have to create (the count number), in order to know
the next id. It is not nice, but I guess it will work. Otherwise I
think I should do a lot of hacking in ODK and maybe javarosa..

My last question would be if calling functions from the calculate
attribute is a supported feature. According to the doc
(http://code.javarosa.org/wiki/xform) it's not, but our forms contain
some calls to the "if" function defined in the XPathFuncExpr class
(e.g: calculate="if(/data/scheduled_fu_visit_date > today(), '1',
'0')") and they are working fine.

Anyway, I'll try and see :wink:

thanks again for your help

pau.

2010/6/11 Clayton Sims csims@dimagi.com:

Pau,
In the code there is a class which is created when a form entry model and
controller is generated called EvaluationContext which maintains the
state
necessary to evaluate XPath expressions during form entry. This class
allows
you to register IFunctionHandler's which can define new functions to be
used
in XPath expressions.
Implementing a function to pull the index of the current repeat would
definitely be tricky, but I believe you could possibly do it with some
assumptions and hacking. You can see the function handling code at

http://www.bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java

You probably want to get an argument as a XPathNodeset or the node itself
and do something like walk up its reference or tree structure until a
repeat
is found, then look for its index.
-Clayton
On Wed, Jun 9, 2010 at 12:06 PM, Pau Varela pau.varela@gmail.com wrote:

hi Clayton and Yaw,

thanks for your replies. yes, access to the current index of the
repeat node is exactly what I would like to do.

My impression was it wasn't supported, but I wanted to verify it.
unfortunately, it seems I was right :wink:

I only have been working with XForms for a couple of months and
looking at the 'pure' XForms documentation, it seems that using the
node's IDREF (I understand it's the XML ID you mention) together with
the index() funtion is possible to access to this value. But after
trying it and reading javarosa documentation, I wasn't able to do it
and that's why I sent here my question. Now at least I know the
reason...

The project I'm working for (eMOCHA) is using already a modified
version of ODK.. when you say "It would be possible to write in this
function into a custom version of ODK which registered a function
handler with the parser as advanced behavior...", how do I register a
function handler? could you please give me some other hint or some
class names so I can take a look at the code?

thanks again,

pau.

2010/6/9 Clayton Sims csims@dimagi.com:

Pau,
To clarify: Are you trying to access the current index of the repeat
node?
IE: Filling out the id field in this sample template?


Clayton
1


Yaw
2


We don't current support the xform function which returns the index of
the
current repeat (because the function's contract requires the repeat to
have
an XML ID, which is also currently unsupported).
We are going to expand the set of supported XPath expressions in a
future
release of our core XForm library, but I'm not sure exactly when that
will
be. It would be possible to write in this function into a custom
version

of
ODK which registered a function handler with the parser as advanced
behavior...
-Clayton
On Tue, Jun 8, 2010 at 9:37 AM, Yaw Anokwa yanokwa@gmail.com wrote:

hi pau,

i understand what you are asking but don't have an immediate
response.

i've escalated to some xforms experts and i'll let you know when i
know...

yaw

On Tue, Jun 8, 2010 at 02:09, Pau Varela pau.varela@gmail.com wrote:

hi,

I have a form with a node like:

and I would like to add a hidden id (called person_id) which is
filled
with the current value of "jr:count".

I've seen XForms doesn't support hidden values because "any values
in

the instance that haven't been bound to by a control are by
definition
not visible to the user".

but I don't see how could I use the jr:count value. I tried by
using

the IDREF of the repeat node and calling it from the bindings:

but it didn't work. I tried also some other possibilities, but I'm
not
even sure 'calculate' is fully supported by javarosa (it works in
some
cases, although in the documentation it's said 'calculate' is not
supported).

Do you have any idea about how to create such 'hidden id' without
having to add an input method? I've seen ODK prints the iteration
number in a 'repeat' loop, but it seems it doesn't use the index
function, but some internal counter.

thanks in advance,

best,

pau.

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

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

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

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

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

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

hi Clayton,

I don't know whether it's an old behaviour (we are using an old ODK
version), but after implementing and testing a new function it looks
to me 'calculate' only evaluates the customized function when the form
is not deserialized.

in the FormLoaderTask class, there is a check to see whether the
binary version of the form exist in the cache directory (.formdef
files). If I manually remove the .formdef file from the device, my new
function is evaluated, but it is not when ODK finds the cached file.

There is anything I can do except for skipping the loading of the
cached files? Which would be the perfomance consequences of ignoring
those cached files?

thanks and regards,

pau.

··· 2010/6/14 Clayton Sims : > Pau, > Calling functions from calculate is a supported feature, that doc is > slightly out of date, sorry. > Additionally, you should be able to get the index of a repeat node from its > treereference (or the treereference of a parent node which is the repeat). > -Clayton > > On Mon, Jun 14, 2010 at 7:08 AM, Pau Varela wrote: >> >> hi Clayton, >> >> thanks for the tip. I've been looking at the code and, as you said, it >> seems not easy, but possible... >> >> I understand I should define my own IFunctionHandler class, like the >> org.odk.collect.android.RegexFunction and let XPathFuncExpr call its >> methods when creating/editing the forms. >> >> Since I don't see how to read, in run-time, the index of a repeat node >> from its binding, I think I'll go for some dirty solution like storing >> temporarily the number of created nodes and check it against the >> numbers of node I have to create (the count number), in order to know >> the next id. It is not nice, but I guess it will work. Otherwise I >> think I should do a lot of hacking in ODK and maybe javarosa.. >> >> My last question would be if calling functions from the calculate >> attribute is a supported feature. According to the doc >> (http://code.javarosa.org/wiki/xform) it's not, but our forms contain >> some calls to the "if" function defined in the XPathFuncExpr class >> (e.g: calculate="if(/data/scheduled_fu_visit_date > today(), '1', >> '0')") and they are working fine. >> >> Anyway, I'll try and see ;) >> >> thanks again for your help >> >> pau. >> >> 2010/6/11 Clayton Sims : >> > Pau, >> > In the code there is a class which is created when a form entry model >> > and >> > controller is generated called EvaluationContext which maintains the >> > state >> > necessary to evaluate XPath expressions during form entry. This class >> > allows >> > you to register IFunctionHandler's which can define new functions to be >> > used >> > in XPath expressions. >> > Implementing a function to pull the index of the current repeat would >> > definitely be tricky, but I believe you could possibly do it with some >> > assumptions and hacking. You can see the function handling code at >> > >> > http://www.bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java >> > You probably want to get an argument as a XPathNodeset or the node >> > itself >> > and do something like walk up its reference or tree structure until a >> > repeat >> > is found, then look for its index. >> > -Clayton >> > On Wed, Jun 9, 2010 at 12:06 PM, Pau Varela wrote: >> >> >> >> hi Clayton and Yaw, >> >> >> >> thanks for your replies. yes, access to the current index of the >> >> repeat node is exactly what I would like to do. >> >> >> >> My impression was it wasn't supported, but I wanted to verify it. >> >> unfortunately, it seems I was right ;) >> >> >> >> I only have been working with XForms for a couple of months and >> >> looking at the 'pure' XForms documentation, it seems that using the >> >> node's IDREF (I understand it's the XML ID you mention) together with >> >> the index() funtion is possible to access to this value. But after >> >> trying it and reading javarosa documentation, I wasn't able to do it >> >> and that's why I sent here my question. Now at least I know the >> >> reason... >> >> >> >> The project I'm working for (eMOCHA) is using already a modified >> >> version of ODK.. when you say "It would be possible to write in this >> >> function into a custom version of ODK which registered a function >> >> handler with the parser as advanced behavior...", how do I register a >> >> function handler? could you please give me some other hint or some >> >> class names so I can take a look at the code? >> >> >> >> thanks again, >> >> >> >> pau. >> >> >> >> 2010/6/9 Clayton Sims : >> >> > Pau, >> >> > To clarify: Are you trying to access the current index of the repeat >> >> > node? >> >> > IE: Filling out the id field in this sample template? >> >> > >> >> > >> >> > Clayton >> >> > 1 >> >> > >> >> > >> >> > Yaw >> >> > 2 >> >> > >> >> > >> >> > We don't current support the xform function which returns the index >> >> > of >> >> > the >> >> > current repeat (because the function's contract requires the repeat >> >> > to >> >> > have >> >> > an XML ID, which is also currently unsupported). >> >> > We are going to expand the set of supported XPath expressions in a >> >> > future >> >> > release of our core XForm library, but I'm not sure exactly when that >> >> > will >> >> > be. It would be possible to write in this function into a custom >> >> > version >> >> > of >> >> > ODK which registered a function handler with the parser as advanced >> >> > behavior... >> >> > -Clayton >> >> > On Tue, Jun 8, 2010 at 9:37 AM, Yaw Anokwa wrote: >> >> >> >> >> >> hi pau, >> >> >> >> >> >> i understand what you are asking but don't have an immediate >> >> >> response. >> >> >> i've escalated to some xforms experts and i'll let you know when i >> >> >> know... >> >> >> >> >> >> yaw >> >> >> >> >> >> On Tue, Jun 8, 2010 at 02:09, Pau Varela wrote: >> >> >> > hi, >> >> >> > >> >> >> > I have a form with a node like: >> >> >> > >> >> >> > > >> >> > jr:noAddRemove="true()" jr:count="/data/household/adults_missing" >> >> >> > id="person-repeat"> >> >> >> > >> >> >> > and I would like to add a hidden id (called person_id) which is >> >> >> > filled >> >> >> > with the current value of "jr:count". >> >> >> > >> >> >> > I've seen XForms doesn't support hidden values because "any values >> >> >> > in >> >> >> > the instance that haven't been bound to by a control are by >> >> >> > definition >> >> >> > not visible to the user". >> >> >> > >> >> >> > but I don't see how could I use the jr:count value. I tried by >> >> >> > using >> >> >> > the IDREF of the repeat node and calling it from the bindings: >> >> >> > >> >> >> > > >> >> > type="int" calculate="index('person-repeat')"/> >> >> >> > >> >> >> > but it didn't work. I tried also some other possibilities, but I'm >> >> >> > not >> >> >> > even sure 'calculate' is fully supported by javarosa (it works in >> >> >> > some >> >> >> > cases, although in the documentation it's said 'calculate' is not >> >> >> > supported). >> >> >> > >> >> >> > Do you have any idea about how to create such 'hidden id' without >> >> >> > having to add an input method? I've seen ODK prints the iteration >> >> >> > number in a 'repeat' loop, but it seems it doesn't use the index >> >> >> > function, but some internal counter. >> >> >> > >> >> >> > thanks in advance, >> >> >> > >> >> >> > best, >> >> >> > >> >> >> > pau. >> >> >> > >> >> >> > -- >> >> >> > Post: opendatakit@googlegroups.com >> >> >> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> >> >> > Options: http://groups.google.com/group/opendatakit?hl=en >> >> >> > >> >> >> >> >> >> -- >> >> >> Post: opendatakit@googlegroups.com >> >> >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> >> >> Options: http://groups.google.com/group/opendatakit?hl=en >> >> > >> >> > -- >> >> > Post: opendatakit@googlegroups.com >> >> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> >> > Options: http://groups.google.com/group/opendatakit?hl=en >> >> > >> >> >> >> -- >> >> Post: opendatakit@googlegroups.com >> >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> >> Options: http://groups.google.com/group/opendatakit?hl=en >> > >> > -- >> > Post: opendatakit@googlegroups.com >> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> > Options: http://groups.google.com/group/opendatakit?hl=en >> > >> >> -- >> Post: opendatakit@googlegroups.com >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> Options: http://groups.google.com/group/opendatakit?hl=en > > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

The cached files are built when a form is first processed and it
results in significant time savings when loading a form the second
time. Clayton, any ideas why the caching would kill calculate?

··· On Monday, June 21, 2010, Pau Varela wrote: > hi Clayton, > > I don't know whether it's an old behaviour (we are using an old ODK > version), but after implementing and testing a new function it looks > to me 'calculate' only evaluates the customized function when the form > is not deserialized. > > in the FormLoaderTask class, there is a check to see whether the > binary version of the form exist in the cache directory (.formdef > files). If I manually remove the .formdef file from the device, my new > function is evaluated, but it is not when ODK finds the cached file. > > There is anything I can do except for skipping the loading of the > cached files? Which would be the perfomance consequences of ignoring > those cached files? > > thanks and regards, > > pau. > > 2010/6/14 Clayton Sims : >> Pau, >> Calling functions from calculate is a supported feature, that doc is >> slightly out of date, sorry. >> Additionally, you should be able to get the index of a repeat node from its >> treereference (or the treereference of a parent node which is the repeat). >> -Clayton >> >> On Mon, Jun 14, 2010 at 7:08 AM, Pau Varela wrote: >>> >>> hi Clayton, >>> >>> thanks for the tip. I've been looking at the code and, as you said, it >>> seems not easy, but possible... >>> >>> I understand I should define my own IFunctionHandler class, like the >>> org.odk.collect.android.RegexFunction and let XPathFuncExpr call its >>> methods when creating/editing the forms. >>> >>> Since I don't see how to read, in run-time, the index of a repeat node >>> from its binding, I think I'll go for some dirty solution like storing >>> temporarily the number of created nodes and check it against the >>> numbers of node I have to create (the count number), in order to know >>> the next id. It is not nice, but I guess it will work. Otherwise I >>> think I should do a lot of hacking in ODK and maybe javarosa.. >>> >>> My last question would be if calling functions from the calculate >>> attribute is a supported feature. According to the doc >>> (http://code.javarosa.org/wiki/xform) it's not, but our forms contain >>> some calls to the "if" function defined in the XPathFuncExpr class >>> (e.g: calculate="if(/data/scheduled_fu_visit_date > today(), '1', >>> '0')") and they are working fine. >>> >>> Anyway, I'll try and see ;) >>> >>> thanks again for your help >>> >>> pau. >>> >>> 2010/6/11 Clayton Sims : >>> > Pau, >>> > In the code there is a class which is created when a form entry model >>> > and >>> > controller is generated called EvaluationContext which maintains the >>> > state >>> > necessary to evaluate XPath expressions during form entry. This class >>> > allows >>> > you to register IFunctionHandler's which can define new functions to be >>> > used >>> > in XPath expressions. >>> > Implementing a function to pull the index of the current repeat would >>> > definitely be tricky, but I believe you could possibly do it with some >>> > assumptions and hacking. You can see the function handling code at >>> > >>> > http://www.bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java >>> > You probably want to get an argument as a XPathNodeset or the node >>> > itself >>> > and do something like walk up its reference or tree structure until a >>> > repeat >>> > is found, then look for its index. >>> > -Clayton >>> > On Wed, Jun 9, 2010 at 12:06 PM, Pau Varela wrote: >>> >> >>> >> hi Clayton and Yaw, >>> >> >>> >> thanks for your replies. yes, access to the current index of the >>> >> repeat node is exactly what I would like to do. >>> >> >>> >> My impression was it wasn't supported, but I wanted to verify it. >>> >> unfortunately, it seems I was right ;) >>> >> >>> >> I only have been working with XForms for a couple of months and >>> >> looking at the 'pure' XForms documentation, it seems that using the >>> >> node's IDREF (I understand it's the XML ID you mention) together with >>> >> the index() funtion is possible to access to this value. But after >>> >> trying it and reading javarosa documentation, I wasn't able to do it >>> >> and that's why I sent here my question. Now at least I know the >>> >> reason... >>> >> >>> >> The project I'm working for (eMOCHA) is using already a modified >>> >> version of ODK-- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en >

In 1.1.2 could this be because line 82 in
FormLoaderTask class will only execute only when there is no cached
object. Could moving
it to line 90 solve it. Funny enough mine works as it is even for cached
forms.

--Sam

··· On 06/22/2010 01:31 PM, Yaw Anokwa wrote: > The cached files are built when a form is first processed and it > results in significant time savings when loading a form the second > time. Clayton, any ideas why the caching would kill calculate? > > On Monday, June 21, 2010, Pau Varela wrote: > >> hi Clayton, >> >> I don't know whether it's an old behaviour (we are using an old ODK >> version), but after implementing and testing a new function it looks >> to me 'calculate' only evaluates the customized function when the form >> is not deserialized. >> >> in the FormLoaderTask class, there is a check to see whether the >> binary version of the form exist in the cache directory (.formdef >> files). If I manually remove the .formdef file from the device, my new >> function is evaluated, but it is not when ODK finds the cached file. >> >> There is anything I can do except for skipping the loading of the >> cached files? Which would be the perfomance consequences of ignoring >> those cached files? >> >> thanks and regards, >> >> pau. >> >> 2010/6/14 Clayton Sims: >> >>> Pau, >>> Calling functions from calculate is a supported feature, that doc is >>> slightly out of date, sorry. >>> Additionally, you should be able to get the index of a repeat node from its >>> treereference (or the treereference of a parent node which is the repeat). >>> -Clayton >>> >>> On Mon, Jun 14, 2010 at 7:08 AM, Pau Varela wrote: >>> >>>> hi Clayton, >>>> >>>> thanks for the tip. I've been looking at the code and, as you said, it >>>> seems not easy, but possible... >>>> >>>> I understand I should define my own IFunctionHandler class, like the >>>> org.odk.collect.android.RegexFunction and let XPathFuncExpr call its >>>> methods when creating/editing the forms. >>>> >>>> Since I don't see how to read, in run-time, the index of a repeat node >>>> from its binding, I think I'll go for some dirty solution like storing >>>> temporarily the number of created nodes and check it against the >>>> numbers of node I have to create (the count number), in order to know >>>> the next id. It is not nice, but I guess it will work. Otherwise I >>>> think I should do a lot of hacking in ODK and maybe javarosa.. >>>> >>>> My last question would be if calling functions from the calculate >>>> attribute is a supported feature. According to the doc >>>> (http://code.javarosa.org/wiki/xform) it's not, but our forms contain >>>> some calls to the "if" function defined in the XPathFuncExpr class >>>> (e.g: calculate="if(/data/scheduled_fu_visit_date> today(), '1', >>>> '0')") and they are working fine. >>>> >>>> Anyway, I'll try and see ;) >>>> >>>> thanks again for your help >>>> >>>> pau. >>>> >>>> 2010/6/11 Clayton Sims: >>>> >>>>> Pau, >>>>> In the code there is a class which is created when a form entry model >>>>> and >>>>> controller is generated called EvaluationContext which maintains the >>>>> state >>>>> necessary to evaluate XPath expressions during form entry. This class >>>>> allows >>>>> you to register IFunctionHandler's which can define new functions to be >>>>> used >>>>> in XPath expressions. >>>>> Implementing a function to pull the index of the current repeat would >>>>> definitely be tricky, but I believe you could possibly do it with some >>>>> assumptions and hacking. You can see the function handling code at >>>>> >>>>> http://www.bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java >>>>> You probably want to get an argument as a XPathNodeset or the node >>>>> itself >>>>> and do something like walk up its reference or tree structure until a >>>>> repeat >>>>> is found, then look for its index. >>>>> -Clayton >>>>> On Wed, Jun 9, 2010 at 12:06 PM, Pau Varela wrote: >>>>> >>>>>> hi Clayton and Yaw, >>>>>> >>>>>> thanks for your replies. yes, access to the current index of the >>>>>> repeat node is exactly what I would like to do. >>>>>> >>>>>> My impression was it wasn't supported, but I wanted to verify it. >>>>>> unfortunately, it seems I was right ;) >>>>>> >>>>>> I only have been working with XForms for a couple of months and >>>>>> looking at the 'pure' XForms documentation, it seems that using the >>>>>> node's IDREF (I understand it's the XML ID you mention) together with >>>>>> the index() funtion is possible to access to this value. But after >>>>>> trying it and reading javarosa documentation, I wasn't able to do it >>>>>> and that's why I sent here my question. Now at least I know the >>>>>> reason... >>>>>> >>>>>> The project I'm working for (eMOCHA) is using already a modified >>>>>> version of ODK-- >>>>>> >> Post: opendatakit@googlegroups.com >> Unsubscribe: opendatakit+unsubscribe@googlegroups.com >> Options: http://groups.google.com/group/opendatakit?hl=en >> >> >