Change country list using postRender

If you want to alter the list of countries on your forms, the following example shows you how to remove a country, rename a country, or potentially insert a new option, all using the postRender callback. Note: if adding a new country, make sure you map it back to an existing value so the address is entered to the system in a way we can process.

var alterCountries = function(args) {
  // Remove a country by the value in the dropdown
   var removalItem = document.querySelector('select[name=Country] option[value="XK"]');
   removalItem.parentNode.removeChild(removalItem);

  // Rename a country publicly (but will map to the existing value in the database)
  var renamedItem = document.querySelector('select[name=Country] option[value="VI"]');
  // desired new text to display
  renamedItem.innerText = 'US Virgin Islands';

  // Insert a new country (not recommended, only use it to map a new entry to an existing value)
  // replace "Dominican Republic" with the name of country that comes right before the country you wish to add
  var previousCountry = document.querySelector('select[name=Country] option[value="EE"]'); 
  previousCountry.insertAdjacentHTML('afterend','<option value="Essos">Essos</option>');
}
var nvtag_callbacks = nvtag_callbacks || {};
nvtag_callbacks.postRender = nvtag_callbacks.postRender || [];
nvtag_callbacks.postRender.push(alterCountries);