Address field allows to add more than one address per field, which is great. However I found that it's not possible to remove any address once it has been added.

I'll give an example of why I think this is a bad behaviour: Let's imagine we have an entity which originally had three different addresses (the postal address and work address is not the same -let's assume that he works in a different contry where he lives). Let's imagine that we want to edit in order to remove the address 2 (because that person started to work at home, so both are the same and the second one is no longer needed) we can delete everything (but the country, which cannot be left empty) but there's no way to delete the whole address. This is annoying because it consumes additional space in node (which can be overwhelming for certain users, specially if we once had several addresses). The problem, however, is worse if we want to display a map wich displays all countries in the entities, because it will display two different locations for the already mentioned entity (remember that that person used to work and live in two different countries?) and it also has to render more information.

Comments

amarcus’s picture

This behavior is actually due to a faulty implementation of hook_field_is_empty(). Drupal's field handling will automatically remove empty fields whenever the entity they are attached to is saved.

However, the addressfield module only considers addresses without a country to be empty. But the country is always set by default, and in fact it is not possible to unset the country field. Hence the duplicate addresses that are impossible to remove.

Better would be to compare the address to the default address.

c-c-m’s picture

You're right, I couldn't have explained it better than you did! Your approach seems good to me (at least when there aren't so many addresses. Another one would be setting a blank country so, whenever was selected, drupal would understand this is an empty country and thus, delete the new address (this would be useful in case we wouldn't want to select any default contry).

joachim’s picture

Status: Active » Closed (duplicate)