After setting up a postal content field to allow for Unlimited values, you can create a new node and add as many address fields as you like by clicking the 'Add another item' button.

This works great but there is a downside. If I decide I only need 3 addresses but I have added 4 fields already, there is no way to remove the 4th field. Also, after saving and then editing the content again, if I had 3 addresses and wanted to save only 2, the 3rd field remains since there is no way to deselect the country dropdown. So 2 addresses would be saved fully and the 3rd would still have the country value since the country field is required.

On a side note, the module is looking great so far. I really am excited to see where it is headed!

Comments

jmcsweet’s picture

I've got the exact same problem. Because the Country field is required, it automatically adds the default country again if you're allowed to add unlimited addresses to your content type.

Interestingly no matter how many empty address fields are added to the edit screen, the country code is still only displayed twice.

You can see the attachments to get a better idea of what's going on.

jmcsweet’s picture

StatusFileSize
new7.33 KB
new32.22 KB

Ok, lets see if my attachments work this time.

jcarlson34’s picture

Those screen shots show visually exactly what I have been experiencing. A picture is worth a thousand words indeed!

jcarlson34’s picture

Perhaps we could add a delete or remove button to fix the issue?

damien tournoud’s picture

You can now remove an address by setting its country to - None -. Not optimal, I agree, but a possible workaround for now.

jcarlson34’s picture

Many thanks Damien. That -None -definitely helps workaround the problem.

afeijo’s picture

A delete link would be more user friendly, as a click is easier than to have to wipe the content of all address fields?
I'll try to add that link

maxchock’s picture

StatusFileSize
new35.15 KB

I got a warning if select the Country to None

Warning: end() [function.end]: Passed variable is not an array or object in file_managed_file_validate() (line 536 of /home/buddyjoy/public_html/modules/file/file.module).

BenjamiB’s picture

Any update on this? the field works but its would be very nice to have additional address showing up only when the first is filled in because the field is quite big...

BenjamiB’s picture

For those interested, I'm using this not very nice but hopefully temporary workaround in order not to populate empty address field :

$delta = $form['field_address']['und']['#max_delta'];
$form['field_address']['und'][$delta]['#address']['country']=NULL;

michaelfavia’s picture

Subscribe.

wabs’s picture

I have the same problem - because the number of addresses is not restricted, on every node save an additional address is generated (with just the default country and nothing else). I don't see the "-None-" option, otherwise it would have been my default country.

@BenjamiB - Thanks for the patch. Where exactly in the module do you insert it?

michaelfavia’s picture

Lets handle the remove button here and the "non-empty fields patch" #1263316: Configurable non-empty value conditions should take care of the extra addresses getting saved.

dgastudio’s picture

patch not applicable to the latest dev.

RobKoberg’s picture

Is this module maintained? Why not simply set the field to default to '- None -'?

Here is another hack (javascript, though). However, even if you set the field to *not* be required, the first Country select does not even have an option to select None...:

function MYMODULE_form_MYCONTENTTYPE_node_form_alter(&$form, &$form_state, $form_id) {
	drupal_add_js('jQuery().ready(function($) {
		$(".field-type-addressfield #field-postal-address-values tbody>tr").each(function(index) {
			var $address = $(this)
			,postal_code = $address.find(".postal-code").first().val()
			,city = $address.find(".locality").first().val()
			,$country = $address.find(".country");
			if ($.trim(postal_code) === "" && $.trim(city) === "") {
				$country.val("");
			}
		});
	});', 'inline');
}

TimelessDomain’s picture

I agree with #13. #1263316: Configurable non-empty value conditions applying this patch automatically removed "empty" address fields upon re-saving the entity.
So now to delete addresses you should just have to clear out the fields then save.

TimelessDomain’s picture

Title: Setting Address Field's number of values to 'Unlimited' allows for adding but not removing addresses fields. » Add "Remove" button to delete addresses
Category: bug » feature
bendiy’s picture

Shouldn't this be a core Fields API issue?

Clearing all the fields and setting the country to "- None -" does not suffice. Normal users do not understand this work around.

bendiy’s picture

joachim’s picture

Category: feature » bug
rszrama’s picture

Title: Add "Remove" button to delete addresses » Add "Remove" button to clear out values in a multi-value address field widget
Component: Code » User interface
Category: bug » feature

I'm not sure I get joachim's comment / recategorization; the link is to this issue.

Since this does appear to be a core concern (see comment #19) and a patch in another issue will also resolve underlying "problem" (see comment #13), I'm going to make this a UI feature request as the kernel that remains is a request to make it easy to clear out an address field value so it is "deleted" on save.

deanflory’s picture

rszrama, do you think you'll be able to get to this soon? Just wondering if I need to consider other options since I believe this is a pretty big concession going from Location Field to Address Field. If a field allows "Add Another", then having an "X" or delete link is pretty much required, any other finagling a user has to do to remove it is simply not friendly at all. Not what I'd expect from taking on a "field" module.

I ask because this is a 2.5 year old issue without any movement, only additional separate duplicate issues and additional requests for the same basic functionality.

kkalaskar’s picture

Issue summary: View changes

Same issue i faced while adding address field for over come this i installed module Multiple Fields Remove Button . Its work for me.

rahul_sankrit’s picture

Same issue i faced for image field and worked for me.

This is for single value deletion from multiple value fields

function custommodule_form_alter(&$form, &$form_state, $form_id) {
  //drupal_set_message($form_id);  // print form ID
    if($form_id==$form_id){
        if(isset($form['field_address']['und'][1])){
              unset($form['field_address']['und'][1]);
        }
    }
}