Expand my Community achievements bar.

Dropdown generates 'month' subforms

Avatar

Level 3

I need a form that includes a dropdown list with a 'months' list - once a month is selected subforms for that month plus the next 2 appear. This form will then be printed for clients to mark particular results on each date. Is this possible, and would the form have to be updated regularly to allow for changes to the months? Thanks.

1 Reply

Avatar

Level 7

Hi,

This will be a start for you.

if ($.boundItem(xfa.event.newText) == "Jan") {

  this.resolveNode('Project._MySubform').addInstance(1);

  if (xfa.host.version < 8) {

      xfa.form.recalculate(1);

  }

  this.resolveNode('Project._MySubform').addInstance(1);

  if (xfa.host.version < 8) {

      xfa.form.recalculate(1);

  }

  this.resolveNode("MySubform[1].TextField1").rawValue = "February"; //adds to first new subform field

  this.resolveNode("MySubform[2].TextField1").rawValue = "March"; //adds to second new subform field

}

Add this to a change event of a dropdownlist.

When "Jan" is selected, a new instance is created of MySubform and February is inserted into the first new instance of the subform (MySubform[1]). Javascript starts with a zero base, so if the new instance isnt specified, it will be placed in the original form. Subforms can be a pain and they have given me much stress over the years. I hope this gives you a start.

This is simple enough to do with the Action Wizard also.

1. Add Action to dropdownlist

2. Condition: When dropdownlist1 "textselected" is Jan

3. Result: Add a New Instance - select your subform - do this twice

4. Result: Set the Value of a Field - select the field you want the month, add the next month eg February, March - do this twice.

5. Click ok.

After it is done, simply edit the code to add [1] and [2] as shown above. this will insert text into the correct form.