3
votes

There is a lot of questions about binding data to forms. This is very simple. I have a form that uses several computed fields that pull data using an @DbLookup to populate the fields based on a pulldown menu the user selects. The problem is; none of the computed fields save any of the values into the form that it is bound to. The only data that saves on the form is the data that is manually selected (in the case of the pulldown menu) or manually entered. When I use an edit box and don't make it "Read Only" the data saves fine. Why is this so difficult?

3

3 Answers

2
votes

Mark - Couple approaches here I think... but let's walk though something.

Read Only on the edit box is preventing the save. It makes sense. XPages should not try to save something marked "read only".

As Steve says, you're better off here with a computed field. Set the values however and if their bound to the document then I think they will save fine.

Another approach is is to work with scoped variables. When you get your data points... you can put that into scoped variables like: viewScope.put("myField", myValue)

then you're computed field could be bound to the viewScope variable "myValue".

however this will of course not save back to the document as it's not bound to the document. So what you do if you want that approach is in the document save event... you then use SSJS to assign the values to the doc then. something like:

document1.replaceItemValue("myfield", viewScope.get("myField");

Since xpages basically has the same document events as notes client. This may seem familiar to you.

Hope this helps.

Dave - NotesIn9.com

Disclamer: I'm answering this from a plane after a trip to Las Vegas. So please factor that into the quality of my answer. :)

1
votes

You will want to put the data you receive from the @DbLookup in an edit box field(s). A computed field is like a "Computed for display" field in traditional Notes development. You can choose whether to allow the user to change the values or not by the read-only property.

Also see this question if you want the values read-only which it sounds like you do: ReadOnly field in Xpage not submitted

1
votes

As usual, Dave steered me to something that worked. Being in the larval stages of JavaScript experience, I'm sure there is a better way to do this. I'm just happy it works. Her is the code I put into the QuerySave event of my Xpage.

var cost1 = getComponent('ItemCost1').getValue();
var uom1 = getComponent('UOM1').getValue();
var Num1 = getComponent('ItemNum1').getValue();
var tot1 = getComponent('Total1').getValue();

docuent1.replaceItemValue("ItemCost_1", cost1), 
document1.replaceItemValue("ItemUOM_1", uom1),
document1.replaceItemValue("ItemNum_1", Num1),
document1.replaceItemValue("CostTotal_1", tot1)

I have 30 iterations of this so it probably works kind of clunky but the operative word is WORKS. If anyone has a better way to get the same results, please post it so I can learn something. Thanks for everyone's help.