Address fields are required.

Previous versions did not require fields to be populated.

Is this currently 'normal' function?

CommentFileSizeAuthor
Address Fields.png8.04 KBguster-von
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Status: Active » Fixed

Yes, that is the correct behavior.
The US mandates that those fields are always present in a postal address.

emilorol’s picture

Hi,

I can see the benefits on having those field forced to be populated in order to have a valid US address, but I am using this module in a lead generation form and more than often the agent only gets the zip code of the client and the address is later on added when the agent call the client back.

Having this module behave this way breaks my workflow, if there any ways to disable this feature and make it work like it was before?

Thank you.

bojanz’s picture

You're free to implement an alter hook like the one I showed in #2282817: How to make only the country required, disabling the safeguards that this module adds.

emilorol’s picture

Perfect, that works.

In case of someone having the same issue:

<?php
/**
 * Implements hook_field_widget_form_alter().
 */
function mymodule_field_widget_form_alter(&$element, &$form_state, $context) {
  if ($context['field']['type'] == 'addressfield') {
    $element['name_block']['name_line']['#required'] = FALSE;
    $element['street_block']['thoroughfare']['#required'] = FALSE;
    $element['locality_block']['dependent_locality']['#required'] = FALSE;
    $element['locality_block']['locality']['#required'] = FALSE;
    $element['locality_block']['administrative_area']['#required'] = FALSE;
    $element['locality_block']['postal_code']['#required'] = FALSE;
  }
}
?>
bojanz’s picture

rjleigh’s picture

While I understand the concept of a complete valid address, the problem is that these fields are required even when the addressfield as a whole is not a required field. So in non-commerce scenarios where collecting an address might be optional, this feature would defeat that use.

I have no problem using the hook (just did), and even modifying it for specific behavior, but there have to be tens of thousands of users of this module who would not be able to do that.

fultonchain’s picture

#4 did the trick for me. Thanks, emilorol.

Herr Lehmann’s picture

#4 also worked fine for me! I think this should be added as an option of Address Field config!

bojanz’s picture

shrimphead’s picture

#4 also worked for me.

Why is there a 'Required field' tag if it set to required by default? That has caused us some big headaches today. Thank you for the form alter.

Status: Fixed » Closed (fixed)

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

jpsalter’s picture

#4 works perfectly. We also realized that if you are collecting more than one address you must have the country default to 'none' otherwise each edit/save cycle adds another address with only a country.