Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use variables for min, max, etc. #309

Closed
avernet opened this issue Jun 14, 2012 · 41 comments
Closed

Ability to use variables for min, max, etc. #309

avernet opened this issue Jun 14, 2012 · 41 comments

Comments

@avernet
Copy link
Collaborator

avernet commented Jun 14, 2012

This is a feature that the data-bound select1 calls for. It would allow form authors to easily create linked data-bound select1 control in Form Builder, e.g. (LHHA and table cells removed for clarity):

<fr:databound-select1 bind="state-bind"
    resource="/xforms-sandbox/service/zip-states"/>
<fr:databound-select1 bind="city-bind"
    resource="/xforms-sandbox/service/zip-cities?state-abbreviation={$state}"/>
<fr:databound-select1 ref="zip" 
    resource="/xforms-sandbox/service/zip-zips?state-abbreviation={$state}&amp;city={$city}">

Without bind names exposed as variables, form authors need to know what the structure of the XML is to refer to the value of another field.

@ghost ghost assigned ebruchez Jun 14, 2012
@ebruchez
Copy link
Collaborator

When done, also update this doc.

@ebruchez
Copy link
Collaborator

ebruchez commented Dec 7, 2013

This should be much easier with the new and improved model variable resolver.

@ebruchez
Copy link
Collaborator

ebruchez commented May 8, 2014

This also makes sense for repeated fr:grid and fr:section so their min and max AVTs can refer to other controls. See #1665.

@avernet
Copy link
Collaborator Author

avernet commented Jan 25, 2016

+1 from community

@ebruchez
Copy link
Collaborator

+1 from me as I was writing an example

@ebruchez
Copy link
Collaborator

See #2910 for a function to access the value of a control.

@ebruchez
Copy link
Collaborator

In an example, I tried to use bind('state-bind'), and it doesn't work, because databound-select1.xbl evaluates its itemset in the inner scope. Using xxf:instance('fr-form-instance')//state works, but it's cumbersome.

Here again, a Form Runner function would help.

@avernet
Copy link
Collaborator Author

avernet commented Apr 25, 2017

+1 from customer who hit the use case mentioned earlier by Erik, and expected to be able to refer to the value of a control when setting the min/max number of iterations in a grid.

@ebruchez
Copy link
Collaborator

+1 from me for min and max in repeated grid. Referrring to $min/$max doesn't work.

@ebruchez
Copy link
Collaborator

+1 from user

@ebruchez
Copy link
Collaborator

+1 from customer

@ebruchez
Copy link
Collaborator

ebruchez commented Oct 25, 2018

See also:

With #2910 implemented, what would it take to make this work? We would like that:

  • the user writes variables in min, max, and other places
  • this gets translated to a function call and back to a variable when editing

Q: How can we do this translation? Parsing and rewriting XPath expressions is not hard, but round-tripping to a string expression is not reliably possible with Saxon. One possibility is to do the rewrite at XBL processing time, at least for fr:grid and fr:section for min and max. This is how it's done now:

<xf:var name="min">
    <xsl:copy-of select="namespace::*"/>
    <xxf:value value="$repeat-context-outer/xxf:evaluate-avt($min-avt)" xxbl:scope="outer"/>
</xf:var>

But we should probably use fr:component-param-value() instead. Entered and fixed #3795.

So which code should do the rewrite of the expression? Should fr:component-param-value(), which translates to xxf:component-param-value(), do it? But then what if somebody wants to use a local variable as the parameter name?

UPDATE: By "local variable" I guess I meant something like for $foo in . return ....

Should other Form Runner code do the translation when assembling the form?

  • decide where the translation takes place
  • implement
  • doc

@ebruchez
Copy link
Collaborator

ebruchez commented Oct 25, 2018

Another way to look at min and max, in particular, is like max-length and the character counter: it could be expressed as a constraint on the grid. The function would check the constraint and annotate the data. fr:grid and fr:section would read the annotated data like fr:character-counter. Doing this, variables would work naturally without any translation, since the constraint is within binds.

One issue with this is to handle backward-compatibility. annotate.xpl could migrate existing forms to use constraints. Form Builder-created forms are unlikely to use expressions which would not run identically in the context of fr:grid and in the context of the binds.

Form Builder would have to read the min and max from the constraint in this case, not from the control.

@ebruchez
Copy link
Collaborator

For fr:databound-select1, this is another story. I don't think we'd like to set the resource name in a bind constraint, would we?

@ebruchez ebruchez changed the title Bind names to be visible in the view as variable Ability to use variables for min, max, and other formulas Oct 25, 2018
@ebruchez
Copy link
Collaborator

After discussion with @avernet, handling min and max as constraints appears like a good solution.

@ebruchez
Copy link
Collaborator

ebruchez commented Nov 2, 2018

Similar requirement for dynamic LHH(A) formulas to be able to refer to variables. See #3807.

@avernet
Copy link
Collaborator Author

avernet commented Jul 11, 2019

+1 from customer to make variables visible in the view, so we can use them in templates

@avernet
Copy link
Collaborator Author

avernet commented Apr 21, 2020

+1 from user who would like to be able to refer to the value of another field with $other-field from the resource URL of a Dynamic dropdown.

@avernet
Copy link
Collaborator Author

avernet commented May 6, 2020

+1 from customer

@ebruchez
Copy link
Collaborator

ebruchez commented Apr 19, 2022

In the model, $foo returns an XML node. However with the current implementation, in the view, we use fr:control-string-value() which returns a string.

  • double-check that $foo returns the node
  • should/could this also be the case in the view, for consistency, in which case we shouldn't use fr:control-string-value()
  • also consider whether $foo should/could return possibly a sequence
  • doc behavior in both cases!

@ebruchez
Copy link
Collaborator

ebruchez commented Apr 21, 2022

So now, in the view, $foo also returns a sequence of items, not a string value.

Added a clarification section in the doc about the variable notation and what it does.

@ebruchez
Copy link
Collaborator

In email templates, "The Form Runner function library is not in scope in this XSLT", and right now we use saxon:evaluate(). If we create an expression which contains frf:controlVariableValue(), we should be able to evaluate it as there is, in fact, an XFormsContainingDocument in scope.

ebruchez pushed a commit that referenced this issue Apr 22, 2022
ebruchez pushed a commit that referenced this issue May 6, 2022
ebruchez pushed a commit that referenced this issue May 18, 2022
- incorrect call to `frf:replaceVarReferencesWithFunctionCalls()`
- handling of `$fr-lang`
ebruchez pushed a commit that referenced this issue Jun 13, 2022
ebruchez pushed a commit that referenced this issue Nov 8, 2022
@ebruchez
Copy link
Collaborator

ebruchez commented Nov 9, 2022

Updated the documentation about renaming.

@ebruchez
Copy link
Collaborator

ebruchez commented Nov 9, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants