Can i use a read-only xf:input act like xf:output in Orbeon?
How to set the value of a readonly input field?
simpler code sample:
<xf:input ref="//Some/Elements/TotalCredit"
value="round(($quantity) * ($creditPerUnit))">
</xf:input >
<xf:output ref="//Some/Elements/TotalCredit"
value="round(($quantity) * ($creditPerUnit))"/>
In the above code the xf:input shows only the initial value from the model!
It doesn't update!
But xf:output value is updated as expected!
So, how can set xf:input's value like xf:output?
I don't want to use calculation in bind.
In your example, you have an xf:input with both a ref and a value; I am not sure what you expect this to do, or if that makes sense, but for sure it currently won't work:
With the xf:output, you can have both a ref and a value, where the node pointed by ref can influence whether the xf:output is shown and the value gives it its value.
If you want to do the same with an xf:input, it can put the result of your calculation in the ref (in your case round(($quantity) * ($creditPerUnit))). If that expression returns an atomic value, then the input field will be readonly, which I think should take care of your situation.
This is how i made it, considering this and this posts.
//First Input
<xf:input ref="//Some/Elements/PreviousInputCreditPerUnit">
<xf:action ev:event="xforms-enabled xxforms-iteration-moved xforms-value-changed">
<xf:setvalue
ref="//Some/Elements/ReadOnlyInputIK"
value="round(($quantity) * ($creditPerUnit))"/>
</xf:action>
</xf:input>
//Second input
<xf:input ref="//Some/Elements/PreviousInputQuantity">
<xf:action ev:event="xforms-value-changed">
<xf:setvalue
ref="//Some/Elements/ReadOnlyInputIK"
value="round(($quantity) * ($creditPerUnit))"/>
</xf:action>
</xf:input>
//Third ReadOnly Input (acts like xf:output)
<xf:input ref="//Some/Elements/ReadOnlyInput">
</xf:input>
Note the action event in the first column of my repeated row:
ev:event="xforms-enabled xxforms-iteration-moved xforms-value-changed"
See this example from Orbeon.
Related
I am coping with the localization of the Date/Time placeholders in form-runner of Orbeon 2018 (albeit it seems this has not been changed in 2019 and 2020 neither).
What I am looking for is defined in orbeon-form-runner.jar\xbl\orbeon\date\date.xbl (and time/time.xbl, but for now, I think it is enough to discuss the first one) file, more specifically here:
<xf:var
name="placeholder"
value="
let $format := xxf:property('oxf.xforms.format.input.date'),
$cleaned := translate($format, '[01]', ''),
$duplicate := replace(replace(replace($cleaned,
'M', 'MM'),
'D', 'DD'),
'Y', 'YYYY'),
$format-en := instance('orbeon-resources')/resource[#xml:lang = 'en']/format,
$format-lang := xxf:r('format'),
$translated := translate($duplicate, $format-en, $format-lang)
return
$translated
"/>
<xh:input type="text" placeholder="{$placeholder}" id="input"/>
The placeholder variable is assembled over the html input, this is clear.
In my language, the YYYY, MM, DD is not the right placeholder for date parts, so my requirement is to change them depending on the current request locale.
At first I tried to extend the labels in the apps/fr/18n/resource.xml, and I replaced the static 'MM', 'DD', etc. constants with xxf:r('components.labels.MM', '|fr-fr-resources|')) and similar things without any success (okay, the placeholder has been displayed, but the same default placeholder that was visible before my modification).
My second approach was to put these labels to the same file, and refer them on the same way: xxf:r('MM'), no success (the same result as in the first case).
My third approach, and I am here now, was to trying to hardcode these static things and only fix these labels for my locale (using an xsl:choose) and here I am: I can't find how on earth could I grab the request locale here (in the context of xbl files).
Neither the <xf:var name="lang" value="xxf.instance('fr-language-instance')"/>, nor the <xf:var name="fr-lang" value="xxf.instance('fr-fr-language-instance')"/> variables pointed to the right current request locale (they showed as "en").
Do you have any idea how to solve this properly?
You define the input format through the oxf.xforms.format.input.date property. And there can be only one input format, which can't depend on the current language.
In the placeholder, the component shows the format you defined through in oxf.xforms.format.input.date, but changing the letter M (month), D (day), and Y (year) to match the current language, and that is done by adding a resource to orbeon-resources, which has currently:
<resource xml:lang="en"><format>MDY</format></resource>
<resource xml:lang="fr"><format>MJA</format></resource>
<resource xml:lang="de"><format>MTJ</format></resource>
<resource xml:lang="pl"><format>YMD</format></resource>
I have my own control, which has model with action which is executing when form is loaded:
<xf:model>
<xf:action ... >
<xf:setvalue ref="???" value="some_value"/>
</xf:action>
</xh:model>
I put this control to my xforms file to the repeatable section:
<section-3>
<section-3-iteration>
<my-control/>
<output-control/>
</section-3-iteration>
<section-3-iteration>
<my-control/>
<output-control/>
</section-3-iteration>
</section-3>
Now I want to reference to the output control from my control, I mean I want to set output-control value inside control. What should I write to ref attribute in setvalue in my control?
I tried to put there: ref="../output-control", but it doesn't work. When I write: ref="xxf:instance('fr-form-instance')//*[name() = 'output-control']" it set value od output-control only in first iteration.
regards
It's a bit dangerous because it violates encapsulation. But if you really need to, try:
ref="xxf:binding('my-binding')/../output-control"
where my-binding refers to your custom control's id attribute on xbl:binding:
<xbl:binding id="my-binding" xxbl:mode="binding" ...>
I have a numeric input field in my form. I just add some format on it with xxf:format :
<xf:input
id="input-control"
bind="input-bind"
class="question nombre"
xxf:format="if (. castable as xs:integer)
then replace(format-number(xs:integer(.),'###,###,###,###,###,###,###,###,###,##0'),',',' ')
else ''">
This may look a bit wild but it's just a format where number 123456 will be presented as 123 456. This works great for me, but not for users...
So now, I added a script to cancel formatting when input is focused (aka : go back to 123456 when editing the field) with a simple js :
<xf:action ev:event="DOMFocusIn">
<xxf:script>
var input = this.getElementsByTagName('input')[0];
var valeur = input.value.replace(' ','');
input.value = valeur;
</xxf:script>
</xf:action>
Behaviour looks ok at first sight, I mean, I entered 123456, focus out and got 123 456 (format ok), focus in and got 123456 (script behaviour ok). But if I don't make any changes on the field and focus out, I don't have the format back (still 123456 instead of 123 456).
I understand that the format is only applied when "needed" and "needed" means here, when the value of the input changes. But if I force an xforms-value-change event I still don't have the format back.
Anyone has an idea on how to achieve this ?
(anyone has understood anything ? :-s)
This can be tricky to get right. I would recommend using instead the fr:number control, which does all of this for you.
I'm trying to set a href attribute of a tag, based on the value of a leaf of the current node in a xforms:repeat. I've tried different syntax, but can't make it work. This is my last try (with a xforms:var). NOTE : the iteration and the list are ok, just the href is not (null pointer exception).
<xforms:repeat id="sous_menu_branches" nodeset="./Branches/Branche">
<xhtml:li>
<xforms:var name="brancheId" value="./BrancheId"/>
<xhtml:a href="/notes-saisie/?brancheId={$brancheId}">
<xforms:output ref="Nom" mediatype="text/html"/>
</xhtml:a>
</xhtml:li>
</xforms:repeat>
Actually, when I try to use xforms:var in my view (view.xsl), I always got a java null pointer error. As example, in the code snippet bellow, the first xforms:output throw an exception, but not the second one (which is supposed to access the same value) :
<xforms:repeat id="sous_menu_branches" nodeset="./Branches/Branche">
<xhtml:li>
<xforms:var name="current-item" value="."/>
<xforms:output id="my-count" ref="$current-item/Nom"/>
<xhtml:a href="/notes-saisie/?brancheId=888">
<xforms:output ref="./Nom" mediatype="text/html"/>
</xhtml:a>
</xhtml:li>
</xforms:repeat>
Can anybody tell me what am I doing wrong ? Thanks in advance !
You don't say which version of Orbeon Forms you are using, but I suspect you are using one which doesn't yet support xforms:var. Try using xxforms:variable instead.
I have a bind definition as follows:
<xforms:bind nodeset="instance('demo')/pointer"
type="xforms:integer"
calculate="
if($current-page < '2') then '0'
else (
if($current-page > '2')
then ($max-pages - 1)
else .
)"/>
For every user click on the form, the current-page value changes. I wanted to understand how often does the calculate in the above the bind defnition execute?
The problem is that the pointer variable and current-page are dependent on each other, so if I click on something first, the value of pointer should be evaluated immediately and in the next instruction I have to set the current-page value based on the pointer value that is changed. On the click, the code will be as below:
<xforms:setvalue ref="$pointer"
value="($pointer + 1)"/>
<!-- i am assuming if the current-page is 2,
it will increment, else the value is set as per calculate -->
<xforms:setvalue ref="$current-page"
value="($current-page + 1)"
xxforms:if="($pointer = $max-pages)" />
When users click on the button (assuming it is a button) that trigger the two xforms:setvalue, those xforms:setvalue run first and the xforms:bind calculate runs later.
Pretty much all users' interaction with the form will cause the xforms:bind calculate to be be reevaluated.