Address Filed - Address Country Dependancy (Address = Dependee)

I have three fields - Select something for Country-X, Select something for Country-Y and Address (Country, Address 1, Address 2, Postal Code, City).
Depending on the Country select of the Address field, I want to show either the Country-X or Country-Y Select fields.
Also - there is several address fields used in this form (lets say e.g. billing and shipping).

This creates several problems that can be solved without having to add hooks or patching modules.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jackbravo’s picture

Sub!

kenorb’s picture

kenorb’s picture

zmove’s picture

Status: Closed (duplicate) » Active

I reopen the issue because I have others problem with addressfield that the one related.

The problem is that you cannot define a field visibiliy depending on the the addressfield value (country for example).

Probably because addressfield is a set of field, conditional fields should probably have some custom code for that addressfield

kenorb’s picture

@zmove:

You can use 'Regular expression' such as 'AT|BE|BG|HR|CY|CZ|DK|EE|FI|FR|DE|GR|HU|IE|IT|LV|LT|LU|MT|NL|PL|PT|RO|SK|SI|ES|SE' or whatever for Address field values match (containing Country values), but make sure that you set 'Custom jQuery selector for dependee' to select.country.

See also: http://drupal.stackexchange.com/questions/106457/how-to-add-a-conditiona...

RedEight’s picture

I'm having a similar issue but it is sort of in reverse. If the dependant is the addressfield and the dependee something like a boolean, the addressfield displays even if I told it to hide unless the boolean is true. I'm not sure if it is related but the addressfield is inside of a Field Group Multiple.

davidczadilek’s picture

Issue summary: View changes

For starters - what I'm trying to accomplish...
I have three fields - Select something for Country-X, Select something for Country-Y and Address (Country, Address 1, Address 2, Postal Code, City).
Depending on the Country select of the Address field, I want to show either the Country-X or Country-Y Select fields.
Also - there is several address fields used in this form (lets say e.g. billing and shipping).

@kenorb: you proposed just this solution - thank you for leading me in the right direction!
Altough some more problems occured - and for future refence to others, I'll go through step by step (not trying to use hooks):

Problem: Some of the address fields are by default required - meaning the parts address1, postal code, and city - probably depending on the country you select.
Now when adding the dependency as described, using the jquery selector and regular expressions, an error occurs that said fields are required.
Solution: To make this work withot having to add a hook - in the address field settings I checked Make all fields optional (Not recommended). Also I unchecked the required option on the address field itself in order to go through step-by-step.

Problem: The dependency still does not trigger right on the form, because multiple address fields are used in this case.
Solution: After inspecting the form and seeing that even the ID of the select field changes when changing the country, adding an id at the end.
I used a wildcard query to omit this --# at the end, e.g.: select[id^=edit-YOURFORM-field-YOURFIELD]

Problem: I still need the address field required.
Solution: I'm pretty sure theres a cleaner solution for this even without using hooks - e.g. using more dependencies - but who'd have known - I just set the requirements in the field settings again as desired - and it still works as desired without throwing any errors in the form.

mobius_time’s picture

I'm having the same problem as RedEight in comment #6, but my AddressField is not inside a Field Group Multiple.

When I create the node with the AddressField, it works on the node create page, but when I display the node it doesn't work.

  • peterpoe committed 0f6d3f3 on 8.x-1.x
    #1199388: Support for Address Field module.
    
    

3CWebDev made their first commit to this issue’s fork.

dqd credited peterpoe.

dqd’s picture

Version: 7.x-3.x-dev » 8.x-1.x-dev
Status: Active » Fixed

Has been committed for 8.x but forgotten to be set to "fixed". Apart from that:

Thanks for the report and all the efforts in here. But due to inactivity in this issue for some years and because of the upcoming EOL of Drupal 7, I will close this issue on the way by cleaning up the issue queue.

Feel free to re-open as "Needs review" if you found a solution or have a patch to be reported to help others on this outdated version.

If you think this issue or missing feature should be addressed in a newer Drupal core 8 and above compatible version of this project, then please file a new issue to the latest dev.

dqd’s picture

Status: Fixed » Closed (fixed)