Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

country/states dropdowns not working correctly in instanced subform

Avatar

Level 2

my dropdowns work correctly however when more addInstances are added the country dropdown (when change event happens)  clears the first instance of the state dropdown only.

eg.

let say i have 6 addinstances with country and state dropdowns. 

when  country canada is changed to america regardless of what  _row it is. it clears the state dropdown in my first _row only

 

       

// This function will populate the state/province Drop-down List for any event EXCEPT the change event.
// This function is called by the initialize event of the state/province Drop-down List.

function getStates(countryField, dropdownField)
{                                             
   dropdownField.clearItems();        // Clear the items of the Drop-down List.
   for (var i=0; i < myCountries.length; i++)    // Look through all the countries until we find the one that matches the country selected.
      if(myCountries[i][0] == countryField.rawValue)  // Check to see if they match.
      {
      for (var j=1; j < myCountries[i].length; j++)  // When they match, add the states/provinces to the Drop-down List.
   {
      dropdownField.addItem(myCountries[i][j]);
     }
   }
}

// This function will populate the state/province Drop-down List for the change event.
// This function is called by the change event of the country Drop-down List.
// The first parameter is simply a pointer to the xfa object model.

function getStatesOther(myXfa, dropdownField)
{                                             
   dropdownField.clearItems();       // Clear the items of the Drop-down list.
   for (var i=0; i < myCountries.length; i++)   // Look through all the countries until we find the one that matches the country selected.
      if(myCountries[i][0] == myXfa.event.newText)  // Check to see if they match. Note: we have to use the event.newText in this case because
   {                                              // the change hasn't been committed yet.
      for (var j=1; j < myCountries[i].length; j++)  // When they match, add the states/provinces to the Drop-down List.
   {
      dropdownField.addItem(myCountries[i][j]);
    }
   }
}

1 Accepted Solution

Avatar

Correct answer by
Level 2

thx for your reply i really appreciate your help

it is the change event that was giving me problems. 

it seemed easier to solve the next day

----------------------------------

form1.purchaseOrder.addcarcheckboxwrap.Table8.detail.country::change - (JavaScript, client)

 

// Update the state/province field when a different country is selected.

 

form1.purchaseOrder.addcarcheckboxwrap.Table8.detail.stateProv.rawValue

countryScript.getStatesOther(xfa, stateProv);

i changed it to

form1.purchaseOrder.addcarcheckboxwrap.Table8.detail.country::change - (JavaScript, client)

// Update the state/province field when a different country is selected.

stateProv.rawValue

countryScript.getStatesOther(xfa, stateProv);

View solution in original post

2 Replies

Avatar

Level 10

May be it would be better to comment after looking at your code in the initialize event of the field.

But I suspect, when calling the function, you might be passing the name of the dropdown instead of the instance of the dropdown.

To avoid this, try passing "this" in the function.

    getStates(countryField, this)

If you still have issues, please share the code in the initialize event.

Thanks

Srini

Avatar

Correct answer by
Level 2

thx for your reply i really appreciate your help

it is the change event that was giving me problems. 

it seemed easier to solve the next day

----------------------------------

form1.purchaseOrder.addcarcheckboxwrap.Table8.detail.country::change - (JavaScript, client)

 

// Update the state/province field when a different country is selected.

 

form1.purchaseOrder.addcarcheckboxwrap.Table8.detail.stateProv.rawValue

countryScript.getStatesOther(xfa, stateProv);

i changed it to

form1.purchaseOrder.addcarcheckboxwrap.Table8.detail.country::change - (JavaScript, client)

// Update the state/province field when a different country is selected.

stateProv.rawValue

countryScript.getStatesOther(xfa, stateProv);