0
votes

I found this discussion which describes how you can put an input text inside a repeat control and repeat it unlimited number of times and bind it to a field in a document dynamically.

Here's what I did. I created a repeat like this:

<xp:repeat indexVar="fieldSuffix" value="#{viewScope.rowCount}">
 <xp:div>
  <xc:dynamicInputText dataSource="#{contact}" fieldName="fullName_#{fieldSuffix}" />
 </xp:div>
</xp:repeat>

In the custom control dynamicInputText I have written the input text control like this:

<inputText value="#{compositeData.dataSource[compositeData.fieldName]}" />

Then I created an Add button on which I increment viewScope.rowCount by 1 and partial refresh the repeat control. This adds a new row of input text. Similarly I created a Delete button on click of which decrement viewScope.rowCount by 1 and partial refresh the repeat control. This removes the last added input text.

Now if click on Add three times I get three input text fields on web page. I enter information in each of them. Then I click on Delete to remove the third (last) input text. Now when I save the data source all three fields (including the last one I removed) gets saved in the document.

Why does this happen? How can I stop the third field I removed to be saved in the document?

1

1 Answers

1
votes

You just hid rendering of that field. Once you binded it, your Delete button must clear its value or remove that item from DDS. For example DDS.replaceItemValue( field, "" ) or (preferably) DDS.removeItem( field ).