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.)
Comment | File | Size | Author |
---|---|---|---|
#13 | addressfield_tokens-webform-hide-country-2550023-13.patch | 1.38 KB | yeebot |
Comments
Comment #2
yeebot CreditAttribution: yeebot commentedComment #3
yeebot CreditAttribution: yeebot commentedFor 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.
Comment #4
yeebot CreditAttribution: yeebot commentedTided 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).Comment #5
kenorb CreditAttribution: kenorb commentedComment #6
kruser CreditAttribution: kruser commentedWorked for me. thanks
Comment #7
marameodesign#4 worked for me too. Thank you.
Comment #8
gapplePatch looks good to me as well
Comment #9
RowboTony CreditAttribution: RowboTony for NuCivic (formerly Nuams) commentedThank you for this patch #4! Works great, and was exactly what I needed in my Webform!
Comment #10
letrotteur CreditAttribution: letrotteur commentedWould 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.
Comment #11
markie CreditAttribution: markie at Mediacurrent commentedPatch failed for me. i think it needs a re-roll from the latest dev branch.
Comment #12
alhena CreditAttribution: alhena at Myplanet commentedAfter update module to 7.x-1.6 patch failed, because it's implemented and modified in the new version of the module.
Comment #13
yeebot CreditAttribution: yeebot as a volunteer and at Torchbox commentedYes, 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.
Comment #14
yeebot CreditAttribution: yeebot as a volunteer and at Torchbox commentedComment #17
lambic CreditAttribution: lambic at New/Mode commentedPatch applied to 7.x-1.x, thanks! 7.x-1.x-dev also updated.
Comment #18
lambic CreditAttribution: lambic at New/Mode commentedComment #20
JeffM2001 CreditAttribution: JeffM2001 commentedWhen 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
Comment #21
joelstein CreditAttribution: joelstein commented