I'm using this script successfully.
form1.#subform[0].typeOfIncidentDdl::change - (JavaScript, client)
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";
if (xfa.event.newText == "associate injury"){
assocInfoSubform.presence = "visible";
} else {
custInfoSubform.presence = "visible";
}
But I'd like to know how I can use number values from the Object palette instead. For a dropdown list, on the Object>Binding tab, I click in the checkbox "Specify item values," where the values are, by default, numbers, and the text is something I specified on the Field tab under "List items." What is the syntax for using those number values instead of text? Here's what I've tried without success.
if xfa.resolvNode(form1.#subform[0].typeOfIncidentDdl).value = "1"; {
[fields become visible and required with error messages]
} else {
[fields are hidden and not required]
}
And this:
var oSubform = xfa.resolveNode("form1.#subform[0].typeOfIncidentDdl.Value");
if (oSubform = 1); {
etc.
And this:
var oSubform = xfa.resolveNode("form1.#subform[0].typeOfIncidentDdl.rawValue");
if (oSubform = 1); {
etc.
I must be close, but I don't quite have the correct syntax. Thank you for pointing me in the right direction.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Good man Jono, I cracked switch statements bases on his examples
I suspect that it is part of the reverse lookup that Paul was explaining.
My understanding (now):
I still think I would use the exit event and rawValue, but "if it's not broken, don't fix it!"
Good luck,
Niall
Views
Replies
Total Likes
OK. This works, sort of.
var oSubform = xfa.resolveNode("form1.#subform[0].typeOfIncidentDdl").rawValue;
if (oSubform = 1) {
assocInfoSubform.presence = "visible";
The subform becomes visible, but when I change the selection in the dropdown, where the value becomes "2," that field doesn't become visible. Here's what the code looks like.
form1.#subform[0].typeOfIncidentDdl::change - (JavaScript, client)
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";
var oSubform = xfa.resolveNode("form1.#subform[0].typeOfIncidentDdl").rawValue;
if (oSubform = 1) {
assocInfoSubform.presence = "visible";
assocInfoSubform.assocNameTxt.validate.nullTest = "error";
assocInfoSubform.assocNameTxt.mandatoryMessage = "Name is mandatory!";
assocInfoSubform.assocStreetTxt.validate.nullTest = "error";
assocInfoSubform.assocStreetTxt.mandatoryMessage = "Street address is mandatory!";
assocInfoSubform.assocCityTxt.validate.nullTest = "error";
assocInfoSubform.assocCityTxt.mandatoryMessage = "City is mandatory!";
assocInfoSubform.assocStateDdl.validate.nullTest = "error";
assocInfoSubform.assocStateDdl.mandatoryMessage = "State is mandatory!";
assocInfoSubform.assocZipTxt.validate.nullTest = "error";
assocInfoSubform.assocZipTxt.mandatoryMessage = "Zip code is mandatory!";
assocInfoSubform.assocDOBDate.validate.nullTest = "error";
assocInfoSubform.assocDOBDate.mandatoryMessage = "Date of birth is mandatory!";
assocInfoSubform.assocGenderDdl.validate.nullTest = "error";
assocInfoSubform.assocGenderDdl.mandatoryMessage = "Gender is mandatory!";
assocInfoSubform.assocPhoneNum.mandatoryMessage = "Gender is mandatory!";
assocInfoSubform.assocPhoneNum.mandatoryMessage = "Phone number is mandatory!";
} else {
custInfoSubform.presence = "visible";
[fields set to .validate.nullTest = "error"; and .mandatoryMessage = "txt";
}
Views
Replies
Total Likes
I also tried this, but it doesn't work.
var oSubform = xfa.resolveNode("form1.#subform[0].typeOfIncidentDdl").rawValue;
switch (xfa.event.newText) {
case (oSubform = 1):
assocInfoSubform.presence = "visible";
break;
case (oSubform = 2):
custInfoSubform.presence = "visible";
break;
}
Or
switch (oSubform) {
case ("1"):
assocInfoSubform.presence = "visible";
break;
case ("2"):
custInfoSubform.presence = "visible";
break;
}
Views
Replies
Total Likes
Phew, it might be easier with the form...
Your #1 post:
It looks like you have an unnamed subform (based on the xfa.resolveNode): ...#subform[0]... I would name this, as I doubt you need to resolve the nodes at all. Name objects as you go!
When accessing the value of the dropdown you need the .rawValue (not .value). This applies irrespective of whether you are binding to specific values or not.
The .value and .rawValue should not be inside the xfa.resolveNode. You should be attempting to resolve the node itself, THEN access the value of that resolved node. In any case I don't think you need the resolve node once you name the subform.
The oSubform test in the if statement need two equal signs: if (oSubform == "1")
Your #2 post:
Same issue - single = in the if statement test.
Your #3 post:
In the change event you would use xfa.event.newText, in the exit event you would use .rawValue.
The syntax for the switch statement is out. The switch statement should contain the current value / users choice. For example
switch (xfa.event.newText){ // for the change event
or
switch (oSubform){ // for the exit event
Then the case lines are simple the appropriate value in quotation marks, for example:
case "1":
// do something
break;
Hope that helps,
Niall
Niall,
Yes, that definitely helps. Here' s what I have now, but it doesn't work.
var oSubform = form1.injurySubformPage1.typeOfIncidentDdl.rawValue;
switch (xfa.event.newText){ // for the change event {
case ("1"):
[one subform becomes visible]
break;
case ("2"):
[another subform becomes visible]
break;
}
I also tried this
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";
if (xfa.event.newText = "1") {
assocInfoSubform.presence = "visible";
} else {
custInfoSubform.presence = "visible";
}
When a selection is made in the dropdown list, only the first subform becomes visible. No matter which choice (there are only two) the user makes, the first subform becomes visible, but never the second.
I also tried this variation, with the same result.
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";
if (typeOfIncidentDdl.rawValue = "1") {
assocInfoSubform.presence = "visible";
} else {
custInfoSubform.presence = "visible";
}
Views
Replies
Total Likes
I just found that if I change the values to a string, the code below works.
switch (xfa.event.newText){ // for the change event {
case ("associate"):
case ("customer"):
And both subforms can appear. Why don't the integers work?
Views
Replies
Total Likes
Hi,
Just on the first one:
var oSubform = form1.injurySubformPage1.typeOfIncidentDdl.rawValue;
switch (xfa.event.newText){ // for the change event {
case ("1"):
[one subform becomes visible]
break;
case ("2"):
[another subform becomes visible]
break;
}
It should look like this IF in the change event of the typeOfIncidentDdl dropdown:
switch (xfa.event.newText)
{
case "1":[one subform becomes visible]
break;
case "2":
[another subform becomes visible]
break;
}
Try that for size,
N.
The number (or value) of the list item is only set after a selection has been made. So if you were testing this on the exit event then you woudl beabel to use the number. In your case you are using the change event and the value that the user selects is not available until after this event. By looking at xfa.event.newText you are probing the keyboard buffer for what was selected and itn that case it is the display item that is being used. You will not be able to get the number unless you do a reverse lookup using the text (which kinda defeats the purpose) until after the selection is made.
Make sense?
Paul
Views
Replies
Total Likes
Yes, that's very helpful and it explains why a string works and an integer doesn't. I didn't realize they behaved differently. Thank you, Paul!
Views
Replies
Total Likes
Yes, I overlooked those parentheses in the case. Thank you for correcting the script.
Views
Replies
Total Likes
In a similar situation on the same form, i have this, which doesn't work. I added from the Hierarchy just to see if that made a difference, and it didn't. What could be missing?
form1.injurySubformPage1.workLocationDdl::change - (JavaScript, client)
injurySubformPage1.sedgwickSubform.presence = "hidden";
injurySubformPage1.benefitsSubform.presence = "hidden";
injurySubformPage1.custServSubform.presence = "hidden";
switch (xfa.event.newText){
case "assocAllExcept":
injurySubformPage1.sedgwickSubform.presence = "visible";
break;
case "assocAll":
injurySubformPage1.benefitsSubform.presence = "visible";
break;
case "custAll":
injurySubformPage1.custServSubform.presence = "visible";
break;
}
I used this, finally, in the other case, and it works fine.
form1.injurySubformPage1.topSubform.typeOfIncidentDdl::change - (JavaScript, client)
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";
if (xfa.event.newText == "associate"){
assocInfoSubform.presence = "visible";
} else {
custInfoSubform.presence = "visible";
}
Views
Replies
Total Likes
Hi,
From here it looks OK, but you could throw in a debug line and look at the Javascript Console (Control+J) when previewing.
console.println("new text: " + xfa.event.newText);
This will at least tell you at runtime what the switch statement is dealing with.
The strings you are testing in the switch statement look like display items?? Are these specified bound values??
Given Paul's explanation, maybe run with the exit event and .rawValue.
Good luck,
Niall
Views
Replies
Total Likes
I did find some code in a forum that got me going, although I don't exactly know why.
http://forums.adobe.com/message/2445121#2445121
Subform Visibility
I implemented Jono Moore's suggestion this way.
form1.injurySubformPage1.workLocationDdl::change - (JavaScript, client)
sedgwickSubform.presence = "hidden";
benefitsSubform.presence = "hidden";
custServSubform.presence = "hidden";
var newValue = this.boundItem(xfa.event.newText);
switch (newValue){
case "assoc":
sedgwickSubform.presence = "visible";
break;
case "benefits":
benefitsSubform.presence = "visible";
break;
case "custserv":
custServSubform.presence = "visible";
break;
}
For some reason xfa.event.newText didn't want to work. If anyone understands what happened in this case, I would be eager to find out the cause. Livecycle scripting is a tremendous tool, and I'd like to continue on my learning curve.
Views
Replies
Total Likes
Hi,
Good man Jono, I cracked switch statements bases on his examples
I suspect that it is part of the reverse lookup that Paul was explaining.
My understanding (now):
I still think I would use the exit event and rawValue, but "if it's not broken, don't fix it!"
Good luck,
Niall
Views
Replies
Total Likes
Niall,
It is always good to hear from you experts! I'll give it a try on the exit event. But it works now! How strange!
Views
Replies
Total Likes
Also you only get one shot at xfa.event.newText .....if you are using it earlier in the script it will be gone the second time you use it. So put it in a variable right away, then you can reuse the variable.
Paul
Views
Replies
Total Likes
Interesting! That's probably what was confusing the issue.
Views
Replies
Total Likes
What you just explained is a problem in this form. Here are the three event scripts I'm using. And you're right. If I use the first script in that dropdown, neither the second nor the third dropdown will work. What is the solution? I'm using a variable, as you suggested. Is there something other than newText that I should use?
form1.injurySubformPage1.workLocationDdl::change - (JavaScript, client)
sedgwickSubform.presence = "hidden";
benefitsSubform.presence = "hidden";
custServSubform.presence = "hidden";
var newValue = this.boundItem(xfa.event.newText);
switch (newValue){
case "assoc":
sedgwickSubform.presence = "visible";
break;
case "benefits":
benefitsSubform.presence = "visible";
break;
case "custserv":
custServSubform.presence = "visible";
break;
}
**************************** later on in form
form1.injurySubformPage1.topSubform.typeOfIncidentDdl::change - (JavaScript, client)
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";
switch (newValue){
case "associate":
sedgwickSubform.presence = "visible";
break;
case "customer":
benefitsSubform.presence = "visible";
break;
}
**************************** later on in form
form1.injurySubformPage2.seekingMedicalTreatmentDdl::change - (JavaScript, client)
physicianSubform.presence = "hidden";
switch (newValue){
case "yes":
physicianSubform.presence = "visible";
break;
case "no":
physicianSubform.presence = "hidden";
break;
}
Views
Replies
Total Likes
Hi,
In the first object the script declares the script variable 'newValue' and this is used in this first object:
var newValue = this.boundItem(xfa.event.newText);
However in the two other objects you use the script variable, but do not declare it or sets its value.
Script objects can only be used within the object in which it is declared. So if you included the above line in the other two objects, then they should work.
Before you do that preview the form and press Control+J to open the javascript console. Interact with the first dropdown and you shouldn't get any error in the console. But when you interact with the second and third dropdown you should see an error along the lines of "newValue is not defined".
When you declare newValue, the two dropdowns should work and you should not see any errors in the console.
Good luck,
Niall
Views
Replies
Total Likes