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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | Set_countrySearch_false_when_preferredCountries_set.patch | 877 bytes | dahousecat |
| #4 | 2626982-38.preferred_countries.patch | 12.98 KB | ericawright |
| #2 | 3097456-1.preferred_countries.patch | 1.94 KB | ericawright |
Comments
Comment #2
ericawright commentedAn 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.
Comment #3
jrockowitz commentedIt 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.
Comment #4
ericawright commentedYep, 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.
Comment #5
jrockowitz commentedComment #6
markie commentedPatch 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
Comment #7
markdc#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
Comment #8
liam morlandComment #9
dahousecat commentedPassing 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.
Comment #10
liam morland6.1.x is not supported. Is this still an issue on 6.2.x? If so, the patch needs to be against that branch.
Comment #11
jrockowitz commentedComment #12
jrockowitz commentedComment #13
jrockowitz commentedA new ticket should be created when #2626982: Allow to set a list of preferred countries is committed.