Reputation: 1343
I know how to bind a computed field to a document field. And I know how to use javascript to compute a computed field. But how do I do both?
Say my javascript in the computed field is:
@Name("[ABBREVIATE]" ,@UserName());
How do I bind that to say document1.ReqName field?
Upvotes: 1
Views: 4417
Reputation: 1
<xp:text escape="true" id="computedFieldTest1">
[CDATA[#{javascript:
var userName = "Username: "+("Reader",@Name("[ABBREVIATE]",@UserName()));
currentDocument.replaceItemValue("computedFieldTest1",userName);
return userName;
}]]></xp:this.value>
</xp:text>
Upvotes: 0
Reputation: 51
Maybe I miss the Point but why don't You simply do the following?
<xp:inputText id="inputText1" value="#{document1.Reader}">
<xp:this.defaultValue>
<![CDATA[#{javascript:@Name("[ABBREVIATE]",@UserName());}]]>
</xp:this.defaultValue>
</xp:inputText>
This is a Textfield bound per EL to the DocumentField. If the field is empty it is calculated by the default value.
Great! - I missed the point. But You can try this one:
<xp:text escape="true" id="computedField3">
<xp:this.value>
<![CDATA[#{javascript:
if(@IsNewDoc()){
document1.replaceItemValue("Reader",@Name("[ABBREVIATE]",@UserName()));
}
return document1.getItemValue("Reader");}]]>
</xp:this.value>
</xp:text>
Upvotes: 1
Reputation: 8465
I wouldn't bind in this case. I would bind every other control and in this case manually add that into the document field directly with script before the save action.
so something like: (forgive the code not at my work comp)
<eventhandler>
<actionGroup>
<script><![CDATA[#{javascript:
doc.replaceItemValue("ReqName", @Name("[ABBREVIATE]" ,@UserName()));
}]]><script>
<saveDocument></saveDocument>
</actionGroup>
</eventhandler>
Upvotes: 0
Reputation: 21709
I use two fields:
Upvotes: 3
Reputation: 91
For the computed field's Value, use Advanced data binding and select Expression Language (EL). The expression to use is simply "document1.ReqName" (no quotes).
Upvotes: 0