Académique Documents
Professionnel Documents
Culture Documents
General
Binding to Lists
Boolean Checkboxes
Custom HTML & Lists of Complex Variables
Warning
This is a legacy wiki article - for the latest information go to Binding Variables Within
Custom HTML.
Warning
Please be aware that this technique is not a part of any documented API for Teamworks.
It is possible that it won't continue to work in future versions of Teamworks. However, this
technique is widely used and so should be safe to apply in your own applications. This code
was tested in Teamworks 5.5.6 - 6.1.
General
Want to use a Custom HTML block on your coach to edit a teamworks variable?
It's really not that hard.
Assume that you have defined a String variable in your service named FavoriteColor.
Within the service where FavoriteColor is defined, you refer to it as tw.local.FavoriteColor... so if you
want to display this value in a CustomHTML block on your coach you can display the value by doing the
following:
That's pretty obvious, but what do you do if you want to edit FavoriteColor on your coach?
The "trick" is in realizing that to bind output to a teamworks variable in your custom HTML, you replace
"." with "#"...
In this example, tw.local.FavoriteColor becomes tw#local#FavoriteColor.
Binding to Lists
Suppose you want a Coach to ask questions from a dynamically generated list, and you want the Coach
to bind all the answers to tw.local.answers. You have two variables:
tw.local.questions (List of String)
Page 1
if(tw.local.questions == null) {
tw.local.questions = new tw.object.listOf.String();
tw.local.questions[0] = "Name:";
tw.local.questions[1] = "Favorite Color:";
tw.local.questions[2] = "Favorite Food:";
}
//init blank answers (answers List length needs to be set so that coach binding will succeed)
tw.local.answers = new tw.object.listOf.String();
for(var i=0; i < tw.local.questions.listLength; i++) {
tw.local.answers[i] = "";
}
Here is an example Custom HTML block that lets you ask the questions and collect all the answers:
The key to making this work is that the List to which the Coach will bind answers must already be
initialized to the required length.
Boolean Checkboxes
When using a boolean variable from teamworks that needs to be changed inside a Custom HTML block
using an HTML checkbox, you can not perform the binding using the checkbox input itself. Instead, you
need to use a hidden input field that is holds the value of the variable. This is done in the following way:
As you can see, there needs to be a "hidden" input that holds the value of the variable as well as a
"checkbox" input. The value needs to be initialized to "true" or "false" according to the initial value that
Page 2
the variable has coming into the coach. Also. the default value for "checked" also needs to be initialized
according to the variable. In this way, the value will be correct, but the check box will also be correct
when the coach displays. The "name" property becomes "BOOLEAN_FOR_[your variable here separated
by hashes]". These are the only values that must change for this example to work for you.
Useful Information
If you want to play around with the properties, you can import the example for your
sandbox.
<TABLE>
<# for(i=0; i < tw.local.subCostList.listLength; i++) { #>
<TR>
<TD><#= tw.local.subCostList[i].code #></TD>
<TD>
<INPUT id='tableRowAmount<#= i #>'
name ='tw#local#subCostList#<#= i #>#amount'
value='<#= tw.local.subCostList[i].amount#>'
onChange='calcTotal();' />
</TD>
</TR>
<# } #>
<TR>
<TD>Total</TD>
<TD>
<INPUT id='tableTotal' name='tw#local#tableTotal' disabled="disabled" />
</TD>
</TR>
</TABLE>
<SCRIPT>
function calcTotal() {
var total = 0;
for(i=0; i < <#= tw.local.subCostList.listLength #>; i++) {
total = total + parseFloat(document.getElementById("tableRowAmount" + i).value);
}
document.getElementById("tableTotal").value = total;
}
calcTotal();
</SCRIPT>
Page 3