Expand my Community achievements bar.

How to Use Switch Statement with Exclusion Group (radio buttons)?

Avatar

Level 7

Wouldn't you know, just when I though I'd really be making progress, I've come across another problem I can't solve. In a homeowners insurance application I am building, there is an exclusion group that needs to set the value of several variables

I have setup in the form properties/variables. These variables take on different values depending on the users choice.  For the exclusion group, in the object pallet, I have set the binding to normal, and have checked the "Specify Item Values" check box. Also the values for the choices have been assigned 1,2,3,4,5.

Here is my code for the change event fir the exclusion group (This is exactly what I have tried). For now, the values for the variables to take on in the different cases, are completely arbitrary.

switch (this.change.rawValue)              // I have tried so many things here
{   
    case "1":                                        // I have tried the caption, single quotes in all combinations
        addLivingExp = "1";
        damageOthersProperty = "2";
        liabilityIncl = "3";
        maxCoverage = "4";
        minCoverage = "5";
        persProperty = "6";
        relatedPrivateStruct = "7";
        break;
    case "2":    
        addLivingExp = "10";
        damageOthersProperty = "20";
        liabilityIncl = "30";
        maxCoverage = "40";
        minCoverage = "50";
        persProperty = "60"
        relatedPrivateStruct = "70";
        break;
    case "3":    
        addLivingExp = "100";
        damageOthersProperty = "200";
        liabilityIncl = "300";
        maxCoverage = "400";
        minCoverage = "500";
        persProperty = "600"
        relatedPrivateStruct = "700";
        break;
    case "4":    
        addLivingExp = "1000";
        damageOthersProperty = "2000";
        liabilityIncl = "3000";
        maxCoverage = "4000";
        minCoverage = "5000";
        persProperty = "6000"
        relatedPrivateStruct = "7000";
        break;   
    case "5":    
        addLivingExp = "10000";
        damageOthersProperty = "20000";
        liabilityIncl = "30000";
        maxCoverage = "40000";
        minCoverage = "50000";
        persProperty = "60000"
        relatedPrivateStruct = "70000";
        break;   
    default:   
        minCoverage= 5;   
        break;
}

There must be something obvious I am missing? Eternally grateful for advice on this.

Stephen

11 Replies

Avatar

Level 10

Hi,

Minor point... I have found that changes to form variables that are driven by script do not hold after the form is closed. The form will revert to the default values that you initially set in the Form/Properties dialogue.

Somethin to bear in mind if you want the form to hold these changes in values.

The switch looks OK to me, but I can test now.

Good luck,

Niall 

Avatar

Level 2

There are two issues in this script:

1. You are not using the accessor 'value' to set form variables

2. You are not correctly getting the value of the radio button list in the switch clause

Please see the working script below.

Ben Walsh

www.avoka.com

switch (this.rawValue) 
{  
    case "1":                                       
        addLivingExp.value                  = "1";
        damageOthersProperty.value   = "2";
        liabilityIncl.value                      = "3";
        maxCoverage.value                 = "4";
        minCoverage.value                  = "5";
        persProperty.value                  = "6";
        relatedPrivateStruct.value        = "7";
        break;


    case "2":   
        addLivingExp.value                  = "10";
        damageOthersProperty.value   = "20";
        liabilityIncl.value                     = "30";
        maxCoverage.value                 = "40";
        minCoverage.value                  = "50";
        persProperty.value                  = "60"
        relatedPrivateStruct.value        = "70";
        break;


    case "3":   
        addLivingExp.value                 = "100";
        damageOthersProperty.value   = "200";
        liabilityIncl.value                     = "300";
        maxCoverage.value                 = "400";
        minCoverage.value                  = "500";
        persProperty.value                  = "600"
        relatedPrivateStruct.value        = "700";
        break;


    case "4":   
        addLivingExp.value                  = "1000";
        damageOthersProperty.value   = "2000";
        liabilityIncl.value                      = "3000";
        maxCoverage.value                 = "4000";
        minCoverage.value                  = "5000";
        persProperty.value                  = "6000"
        relatedPrivateStruct.value        = "7000";
        break; 


    case "5":   
        addLivingExp.value                  = "10000";
        damageOthersProperty.value   = "20000";
        liabilityIncl.value                      = "30000";
        maxCoverage.value                 = "40000";
        minCoverage.value                  = "50000";
        persProperty.value                  = "60000"
        relatedPrivateStruct.value        = "70000";
        break; 


    default:  
        minCoverage.value                 = 5;  
        break;
}

Avatar

Level 7

Niall,  Thank you, for your reminder! I won't need to save those values, but it is a very good thing to be aware of for the future.   Stephen

Avatar

Former Community Member

There is a checkbox on the Form Properties/Defaults tab for scripting. Ensure that the checkbox for Automatically is checked. This will save your script state changes when you save the form.

Paul

Avatar

Level 7

Thank you, Paul. That is valuable information,  I very much appreciate the interest in this.by the folks that have posted.

I am STILL having difficulty with this.  I created a separate "test" form, without any other added scripting. I included both numeric and text fields for the updated variable values (in case that makes a difference). I  have both a drop-down box and an exclusion group (again, in case that makes a difference). I think it is likely the scripting would be somewhat different for these, and it would be great to understand the difference. I'd like to be able to make both work.

Attached is the "test" form. I am thinking there must be a simple adjustment to the code or settings to make this work. I have tried every scenario I can think of. The goal is to have the new variable values.appear in the numeric fields. Is it possible that the problem lies with the numeric fields' coding?

This is an essential part of a large project I'm working on and solving this will be a huge help.

Stephen

Avatar

Level 7

The attachment from my previous post is finally available for download:



A simple problem in search of a simple solution.

Thanks

Stephen

Avatar

Level 10

Hi Stephen,

The switch statement is OK, but it appears that the calculate event is not firing when the dropdown event executes, because the two objects are not directly related.

I am attaching your file. I have (temporarily) added a console.println statemet which shows that the switch statement is working (when previewing in Acrobat press Control+J).

I also turned off the script in the radiobuttons, to concentrate on the dropdown.

I have added a series of NumericField1.menuExec("calculate"); script after the switch statement, to fire the fields; "relayout" did not appear to work.

Hope this helps.

Niall

Avatar

Level 10

Hi Paul,

I have tried that before, but still cannot get the changes in the global variables to be saved with the form.

For example in Stephen's file, I cannot get the changes in var1, var2, or var3 to be saved with the file. When the file is reopened var1 = 123 again.

I have tried this in my own forms and other examples, but cannot get the changes in global variables to be persistent.

To generate a global variable I am going to the Forms/Variable tab and adding a variable. At this stage I have to give it an initial value. The global variable then appears in the hierarchy and I can use it in scripts. I can also change it's value via script. But everytime I save the file and reopen it, the global variable reverts to the initial value that I gave it in the Forms/Variables tab.

I am working around this, but would like to get a solution.

Thanks,

Niall

Avatar

Level 7

Hi Niall,

I very much appreciate your efforts here, and I have gleaned some insight from your suggestions.

Now that I understand that be have to get the calculate event to execute, I modified your approach somewhat. Instead of specifying individual fields to execute calculate, I have the entire form do it using:

form1.execEvent("calculate");

after the switch statement. It works! (granted this might cause some problems for me later on and I may have to be more specific)

I am not sure why it is necessary to kick start the calculate event into firing (except that it won't do it in response to a variable value change?)


From the Help documentation:


Caculate initiates in the following situations:


•  When your form design and data merge into your finished form. 


•  When a change occurs to any value that the calculation is dependent on, such as the value of a particular field, unless the form filler has manually overridden the calculated value. As a result, the object will display the return value of the event. The properties for manually overridden fields are located in the Value tab of the Object palette.


•  When a field loses focus; for example, when a form filler clicks or uses the Tab key to exit a field.

So, it would seem that it would not be necessary. Anyway, I'm happy I have an solution for now.

With regards to saving the variable values when the form is saved by the user--this is not a concern for me, right now..

Thanks,

Stephen

Avatar

Level 10

Hi Stephen,

Glad you got it working.

I would agree with you, I would have expected the calculate event to fire; however it appears that the calculate event will fire when a dependent value in another field changes and not automatically when a referenced form variable changes. Form variables are contained in the Form DOM, but objects seem to not track if these are changed. It was clear that when the form was merged/opened the calculate event accessed the form variables. The Javascript console showed that while the switch script was working, the new values were not picked up in the calculate event. Relayout didn't appear to work either.

Someone may be able to explain why this is the case!

Depending on the number of fields with calculate events, there may be performance considerations if all of these events are executed everytime the dropdown is accessed.

N.

Avatar

Level 1

Stephen, thanks for sharing your tips. Is it possible to post the script calculation in full so  may see the full string of commands? I have a similar problem and would appreciate any assistance.

Christina Rose