Now you can only set the entire address as required.
I think it would it be useful to have a checkbox next to each individual field to allow the field to be required or not? For example to make sure you get at least the zipcode.

Comments

xlyz’s picture

michaelfavia’s picture

@kriboogh This module seems to be implemented with the desire to keep things as simple as possible (which i agree with). Unfortunately this principle might be slightly at odds with the increasing prominence of the module as the default address storage mechanism for drupal 7. The diversity of address formats may also play into the consideration not to allow this as the setting might have to be stored per country allowed (this is just an educated guess).

As Geofield and geocoder mature and this module develops into the defacto standard there will undoubtedly be more need for features of this type (the name field on the widget also has an issue relating to this).

Adding your feature would be simple and i could use it myself (currently form_altering) but i think that it might be outside of scope for the module maintainers use case as he uses it for Drupal Commerce which obviously needs full addresses to ship packages, etc.

@ryan any feedback welcome. Ill post a patch/drop the issue with a little direction.

damien tournoud’s picture

The -reloaded branch has been merged. It comes with many refactored things, including new required fields. Feedback welcome, as I think we might need to improve this again.

marcus_w’s picture

@damien Which version should I use to see the required fields? I'm using 1.0-beta1, but can't find the settings. Can't find it in -dev as well..

damien tournoud’s picture

Status: Active » Closed (won't fix)

I'm sorry, but we are not going to support per-field required settings in the UI. You can easily implement an address format plugin for this (see the examples in the module code).

seanr’s picture

Status: Closed (won't fix) » Active

Damien, the problem with your suggestion is that is a per-country implementation. I really cannot reasonably be expected to copy all of the possible country formats (I'm dealing with an international site) and modify every one of them to just to add a required setting to specific fields (in my case, organisation). Is there any particular reason why this cannot be done through the addressfield module itself? I can implement hook_form_alter for sure (although the addressfield form structure is rather opaque), but really, shouldn't this be an option within the UI?

seanr’s picture

Version: 7.x-1.0-alpha1 » 7.x-1.x-dev

changing version

perarnet’s picture

I agree this is needed, for example thoroughfare is a value that is not used on all adresses in my country. To have to programmatically change the settings for every implementation of addressfield is really a setback for ease of use.

that0n3guy’s picture

Its easy to "un-require" stuff in a module. Here is an example of un-requiring the street address and zip:

/**
* Implements hook_form_alter().
*/
function yourmodulenamehere_form_alter(&$form, $form_state, $form_id) {
  //don't force required fields.
  if ($form_id == 'yourcontenttypenamehere_node_form') { 
    $form['yourfieldnamehere']['und'][0]['street_block']['thoroughfare']['#required'] = FALSE;
    $form['yourfieldnamehere']['und'][0]['locality_block']['postal_code']['#required'] = FALSE;
  }
}
magicmyth’s picture

Sorry to bump this but IMHO the suggestion above is not the best work around to this as its all too easy to find the form structure has changed for multiple reasons (e.g. another module already made an alteration). A more reliable place to make such an alteration is with hook_field_widget_WIDGET_TYPE_form_alter() like so:

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 *
 */
function YOUR_MODULE_field_widget_addressfield_standard_form_alter(&$element, &$form_state, $context) {
  // Alter or remove this line to suit your needs
  if ($element['#entity_type'] != 'node' || $element['#entity']->type != 'your_node_type') return;

  $element['locality_block']['postal_code']['#required'] = FALSE;
}

This way you do not need to be concerned with things like translations, deltas and other low level parts.

As for the topic. I'd like to put forward a use case for controlling which fields are mandatory as I've just had a client who is listing events on their site. These events can be out in places without post codes (many are in fields, on moors). This is a common enough use case and expecting an administrator to dive into the code is quite user unfriendly. I know there is a desire to keep from cluttering the UI but many parts are already configurable (optional country specific, name, organisation) and we are talking about something only a site administrator deals with and only on rare occasions. I don't see it as causing much hassle in using the UI if the required state of the UI is configurable.

seanr’s picture

Fantastic advice, magicmyth. I wonder how hard it would be to wrap this up in a contrib module that allows configurability on a per-field, per-node basis. I might take a whack at that.

rootwork’s picture

I'd love to see this as an add-on contrib module, if per-field support isn't possible within the module itself. Do report back seanr!

iwant2fly’s picture

I am also seconding a request for this seanr. I would be happy to bug test and or possibly throw a little $$ your way.

seanr’s picture

Still on my radar, guys, just been slammed lately.

Kristina Katalinic’s picture

I am having a similar problem here. Don't need Address1 and Address 2 fields at all.
I was trying to get rid of them using example.module and plugin file address .inc but that lead to errors.
If anyone has a solution for this I'd really appreciate it

matthijs’s picture

I think the patch in #1263316: Configurable non-empty value conditions can be used to solve this issue?

System Lord’s picture

Issue summary: View changes

Any movement with this, seanr?

System Lord’s picture

#10 will this work in profile2 ? Instead of: 'your_node_type' what would I use to reference this in a profile form field for addressfield?

This will be a nice feature as I as need 5 required street fields, 2 optional, and 2 that I don't even need to display.

yekezei’s picture

You can also use https://drupal.org/project/field_validation and set individual fields as required

rootwork’s picture

Thanks! That's definitely helpful, although I think this kind of functionality is pretty fundamental and should be core to addressfield. The cases in which some but not all parts of the address are required are quite frequent.

Just my two cents.

System Lord’s picture

+1

held69’s picture

Without succes i tried to make my postal_code field required using with #9:
$form['field_adres']['und'][0]['locality_block']['postal_code'][#required]=True;

However using dpm my postal_field mentioned:
#required (Boolean) TRUE

Strange thing is that i can hide my postal_code field with:
hide($form['field_adres']['und'][0]['locality_block']['postal_code']);

Also setting the address field (including all the fields) required is no problem:
$form['field_addressfield']['und'][0]['#required'] = TRUE;

Help appreciated

thanks

bojanz’s picture

Status: Active » Closed (duplicate)