Click on any phrase to play the video from that point.
[♪music♪]
[ADOBE® LIVECYCLE® ES2]
[male] Hi, this is Duane Nickel.
I'm going to show you how to use LiveCycle Designer from ES2
to use a form with a Switch-Case statement instead of an If-Else.
We'll start with a brand new form, call it NewForm5,
and start out by dragging a DropDownList on
and then we can take a text field, and what we'll do is set up the text field
to reflect the value selected from the DropDown list.
And in order to do this--the dropdown list--
we'll have to add we'll have to add some patterns to it so we'll give it some values:
a value 1, and we'll do 1 through 3
just to make sure that we have enough to work with.
Now, the real value of this is if you had a very long set of values,
you wouldn't want to necessarily have to go if and then test against all of these conditions.
A Case-Switch statement can be used much more effectively.
In a large form, a good strategy would be to use a dynamic data provider
and based on other choices earlier on in a form,
to then create the array of values in a way that the most likely choices would be near the top.
This is quite often done with country and province or country and state fields.
If you choose the country first, then the subset is much smaller.
It takes less time to load a smaller subset, and hence less processing time
to actually test to see which one was done.
Now, if we wanted to use Action Builder to do this, we could.
This is a new feature in LiveCycle ES2.
The Action Builder we can say when an object DropDownList1 --when it's changed
set the value of a field and we'll set the value of the text field one
to the value of the field and we'll say DropDownList.
Now, when we've completed this,
we can go back and look at the name of the DropDown field
and we'll see in it that the code's being generated for us
and this is--again--it's a brand new feature.
This code should not be edited.
The code has comments on the front, but it does resolve the node text field
when it set its raw value to be bound to the DropDown list first instance,
which we have to wait to come across.
To see this working, we can go to the PDF View of it
and we'll just quickly demonstrate that it works.
When we click value1, it populates the field;
value2, value 3, etc., so this is already working good.
But again, if you have a very large data set, this is not always the best way
to go through this, so let's remove this DropDownList from our form
and start from scratch again, and we'll add a new DropDownList.
And again, we'll set the value of the object on here: value1, value2, value3.
And now, we can capture this; by default the best event for this particular form
which would be the Exit button
and we can do a Switch-Case statement, so just using the code editor
which we can adjust just by moving this line up and down.
We can now take the switch and we're going to use the keyword "this"
and we'll use the raw value instead of value.
Raw value will compare the literal value of it.
And then, we'll enter into the switch statement and the case statements.
The case statements--you simply write case
and then the literal value, which would be "value1" in this case,
and then we put a full colon rather than a semicolon,
and what we would do is then set TextField1's raw value, so we'll say Text,
and this note--this is case sensitive--
TextField1.rawValue = and we can then add DropDownList--
and we should have given these shorter names--rawValue.
And the last part of this is a break statement. No
Now, the break statement, basically tells the system to break
after it gets a positive result, so if this tests true,
if the case in fact is value1, we could do that.
Now, this is not something--a construct that you would use
because this is sort of an illogical construct.
Basically, what we're doing is we're setting the value of the TextField
to whatever the value is of the DropDownList,
and there's a number of better ways to do this.
Now, this is to demonstrate the Case and Switch statement working.
So we've got this code complete.
It's very, very simple, and now we'll run this
and it should have the same effect as we did before.
We select value1, it sets it to value1.
In the case that it's value2, it selects value2; value 3, etc.
Now, again, this typically--if you were just changing the value of a single field
like this, you would use a value--a text field equals the DropDownList field
on the exit of the DropDownList, but if you wanted to manipulate
three or four different subform groups or complete things in and around the form,
a Case-Switch statement can actually be a very, very handy construct for coding.
I'm Duane Nickel and I hope you enjoyed this episode.
This is another set of hints for working in LiveCycle Designer on ES2.
[ADOBE® TV] [tv.adobe.com]


