Title: xpages set a value to a field from a repeat field
Tags: xpages
Question: I'm trying to set a value to a field ( which is not inside the repeat control ) from a field which is on the repeat control.
The field from the repeat:
<xp:inputText id="inputText2" disabled="true"&gt;
<xp:this.value&gt;<![CDATA[#{viewScope.field_2[index]}]]&gt;</xp:this.value&gt;
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="sus"&gt;
<xp:this.action&gt;<![CDATA[#{javascript:getComponent("inputText4").setValue("1234");}]]&gt;</xp:this.action&gt;
</xp:eventHandler&gt;
</xp:inputText&gt;
And the target field , as you can notice, is inside a panel, id="sus".
Also the target field is binded to a form field.
but no value is assigned. How can I achieve this?
Comment: @PaulStephenWithers In the same event I've added another line: getComponent("inputText1").setValue("1234") // where inputText1 is a repeat field. The value has been added for this field, but not for the above field ( which is outside the repeat control )

Comment: No. inputText4 is outside the repeat control

Comment: Is your SSJS being triggered?

Comment: Do you have an inputText4 control also within the repeat?

Here is the accepted answer: Components are only visualizations of a data model behind. Always bind your controls and go after the model value, never the component. A disabled inputText can't fire a value and in the code snippet above you have disabled="true". The onchange event can't fire.
This would work:
<xp:inputText id="inputText2" disabled="false"&gt;
<xp:this.value&gt;<![CDATA[#{viewScope.field_2[index]}]]&gt;</xp:this.value&gt;
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="sus"&gt;
<xp:this.action&gt;<![CDATA[#{javascript:viewScope.someValue=42;}]]&gt;</xp:this.action&gt;
</xp:eventHandler&gt;
</xp:inputText&gt;
Your target control would look like this:
<xp:inputText id="inputText4" value="#{viewScope.someValue}"&gt;
</xp:inputText&gt;
If your target control is bound to something else (e.g. #{document1.test}), they your code needs to update that one. (document1.replaceItemValue("test",42))
Again 3 important aspects:
Never go after UI elements, always update the bound model behind (a.k.a: Talk to the data, not the UI also known as: The Controller updates the MODEL, not the view)
Make sure your target is part of the refreshed fields
Disabled fields don't fire events
Let us know how it goes
Comment for this answer: Thanks for your response. 1. I've added the question code in the onChange event of a field which isn't disabled, but still no work. 2. After adding a value to a viewScope, how can I then pass it to the respective field ( from outside the repeat ) which is already binded to a form field?
Comment for this answer: thank you for your great tips & explanations. Have a nice day.
Comment for this answer: Complete code would yield complete answers. You didn't mention that your target field is bound to a data source. Doesn't change much of the solution. Talk to the DATA, not the UI! Solution updated above


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:10/06/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<xpages>', 'Title': 'xpages set a value to a field from a repeat field', 'ViewCount': 489, 'id': 26211032, 'user_AboutMe': '<p><strong><em>“Tell me and I forget, teach me and I may remember, involve me and I learn.”</em></strong></p>\n', 'user_AccountId': 1397398.0, 'user_DisplayName': 'Florin M.', 'user_Reputation': 2159.0, 'user_Views': 609.0, 'user_id': 1326910.0}}