Following on from https://www.drupal.org/node/2352095 (7.x-1.4) it would be useful to have an option in the Webform implementation to allow the admin to hide the country select field if there is only one available option (as per the implementation on the Addressfield field handler).

I've created a new patch which is essentially Tyler Pepper's patch from his original feature request above - although I had issues getting it working on version 7.x-1.5 of the Addressfield Tokens module so have replicated it for this version. (Sorry if this isn't the correct place for it to go and let me know if it should be moved elsewhere.)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yeebot created an issue. See original summary.

yeebot’s picture

yeebot’s picture

For the "hide country" option to be useful we also need to have the missing default country option in place as detailed on https://www.drupal.org/node/2434707. I've created a new patch which also includes the code from that patch. This will enable you to simply display the other address fields without having to select a country first on webform when you only have a single country.

The configuration to achieve this does seem a bit convoluted at the moment though as to achieve this you need to select an available country, default country and tick the hide country box. So this could probably be much improved.

yeebot’s picture

Tided up the patch to resolve Notice: Undefined index: hide_country_field in _webform_render_addressfield() notices and only hide the country field when other conditions are satisfied (i.e. only one available country which matches the default country).

kenorb’s picture

Status: Active » Needs review
kruser’s picture

Worked for me. thanks

marameodesign’s picture

#4 worked for me too. Thank you.

gapple’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

Patch looks good to me as well

RowboTony’s picture

Thank you for this patch #4! Works great, and was exactly what I needed in my Webform!

letrotteur’s picture

Would be great if we could use format_handler to resolve this issue. See issue: https://www.drupal.org/node/2500211.

The remaining problem seems to be that webform component array structure seems to be fundamentally different from field array stucture. So I don't know if there is a easy way to make addressfield_tokens play nicely with addressfield format handler.

markie’s picture

Status: Reviewed & tested by the community » Needs work

Patch failed for me. i think it needs a re-roll from the latest dev branch.

alhena’s picture

After update module to 7.x-1.6 patch failed, because it's implemented and modified in the new version of the module.

yeebot’s picture

Yes, I see that there is a new Format handler checkbox for "Hide the country when only one is available" in version 7.x-1.6 now. However this doesn't seem to work for me. I believe the reason is because the webform component value to check for is whether the field is "mandatory" rather than "required"?

I've made a couple of tweaks (which incidentally also resolves the issue with the Address field label not being displayed with the asterisk indicating a required field) and included an updated patch below which should work with 7.x-1.6 and the current version of 7.x-1.x (both of which seem to be quite far ahead of 7.x-1.x-dev).

This now hides the Country field for me when the address is mandatory and there is only one option.

yeebot’s picture

Status: Needs work » Needs review

  • lambic committed 7428b21 on 7.x-1.x authored by yeebot
    Issue #2550023 by yeebot: Hide the Country select field on webforms when...

lambic credited lambic.

lambic’s picture

Patch applied to 7.x-1.x, thanks! 7.x-1.x-dev also updated.

lambic’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

JeffM2001’s picture

When using the latest dev version, which includes patch #13, I get notices for "Undefined index: mandatory". Unless I'm missing something, it seems that "mandatory" was changed to "required" back in 2013. See: #2020723: Rename "mandatory" to "required" for consistency with HTML5 and the rest of Drupal

joelstein’s picture