When adding an address field to a webform we can't specify priority countries. There is current work that is being done to make this a possibility for the Address module in general, but it causes an error when we add an address field to a webform and doesn't give us any control over it within the webform.

Steps to Repeat:
1. Apply patch from https://www.drupal.org/project/address/issues/2626982 to the Address module
2. Add an address field to a webform
3. View the webform and see this error message: "Notice: Undefined index: #preferred_countries in Drupal\address\Element\Address::processAddress() (line 195 of modules/contrib/address/src/Element/Address.php)."

I'm going to work on combining the new functionality from the Address module with the Webform module.

Comments

ericaascott created an issue. See original summary.

ericawright’s picture

An updated patch from the Address module is necessary for this to work and I've also included the patch for webform in order for this to work with this.

I'm sure this isn't something that will be included in the project anytime soon (or at all) but it was functionality I needed so I thought I'd share what I came up with.

jrockowitz’s picture

Status: Active » Postponed

It seems like the patch in #2626982: Allow to set a list of preferred countries will be committed in the near future. The patch just needs some test coverage.

I am switching the status of this ticket to 'Postponed' since the Address module needs to be updated first.

ericawright’s picture

StatusFileSize
new12.98 KB

Yep, I had no expectations that my work would be included, I just wanted to share what I came up with in case anyone else was like me and needed this functionality now. Thanks!

Also, there was an issue with my patch for Address so I'm re-uploading a fixed one.

jrockowitz’s picture

Title: Allow to set a list of preferred countries on address field » [Address 8.x-1.x] Allow to set a list of preferred countries on address field
markie’s picture

Patch does not apply on 6.0.5

EDIT: One day I'll learn to read. The Address module patch does not apply on the Webform module. However if you properly apply the supplied patch for Address, and the Webform patch, not only does it apply, it also works as advertised. Doing some testing before setting as RTBC

markdc’s picture

#4 applies to Address 8.x-1.11 but I'm having trouble.

The Basic Address field shows no limitation options.
The Advanced Address field does. However trying to save the field results in this error:

Warning: Undefined array key "#preferred_countries" in _webform_entity_element_validate_rendering_error_handler() (line 1076 of /var/www/vhosts/quadroworld.com/drupal_stage/web/modules/contrib/webform/webform.module)

EDIT: Forgot to mention I'm on Drupal 9.5.3, Webform 6.1.4, PHP 8.0.27

liam morland’s picture

Version: 8.x-5.x-dev » 6.1.x-dev
dahousecat’s picture

Passing the preferredCountries to intlTelInput only works if countrySearch is turned off.
This is documented on this page under the preferredCountries section.

This is a simple 1 line change in js/webform.element.telephone.js to disable countrySearch when preferred countries are set.

I've attached a patch which is against 6.1.x.

liam morland’s picture

6.1.x is not supported. Is this still an issue on 6.2.x? If so, the patch needs to be against that branch.

jrockowitz’s picture

Version: 6.1.x-dev » 6.2.x-dev
jrockowitz’s picture

Version: 6.2.x-dev » 6.3.x-dev
jrockowitz’s picture

Status: Postponed » Closed (outdated)

A new ticket should be created when #2626982: Allow to set a list of preferred countries is committed.