I have created a content type, enabled a single location, and configured the collection settings so the location fields are displayed on the node edit form in the following order:
Location name (weight: 1)
Street location (weight: 2)
Additional (weight: 3)
City (weight: 4)
State/Province (weight: 5)
Postal Code (weight: 6)
Country (weight: 7)

The problem is that on the node edit form, the 'Additional' field is always displayed before the 'Street location' field. I even went as far as setting the 'Street location' weight to -100 and the 'Additional' field weight to +100, but still the 'Additional' field was displayed directly before the 'Street location field'. I went into the code and noticed this (near line 210, location.module):

// Only include 'Street Additional' if 'Street' is 'allowed' or 'required'
if ($field == 'street' && $fsettings[$field]['collect']) {
  $element['additional'] = location_invoke_locationapi($defaults['additional'], 'field_expand', 'additional', 1, $defaults);
  $element['additional']['#weight'] = (int)$fsettings[$field]['weight'];
}

It appears that this code is overriding the custom 'Additional' field settings I set in the collection settings. It sets the weight of the 'Additional' field to the same as the 'Street location' field, and since 'Additional' comes before 'Street location' alphabetically, it is always displayed before 'Street location'. My guess is that this is some old code that was needed before it was possible to manually control the 'Additional' field's display. Now that we can, this code should probably be removed.

Comments

pathfinderelite’s picture

Status: Active » Needs review
StatusFileSize
new835 bytes

Here is a patch that simply removes the unnecessary section of code.

vegagitator’s picture

Deleting that code worked for me. Yay! Thank you.

j0rd’s picture

Changing this in location.module . My code is for DRUPAL-6--3-0.

// Only include 'Street Additional' if 'Street' is 'allowed' or 'required'
if ($field == 'street' && $fsettings[$field]['collect']) {

to this...

// Only include 'Street Additional' if 'Street' is 'allowed' or 'required'
if ($field == 'street' && $fsettings[$field]['collect'] && $fsettings['additional']['collect']) {

..resolves the issue. I believe the author of this code only wanted to display "additional" if street is set to display and additional is set to display. If Additional is set to display and street isn't, he didn't want Additional to show up. Additional is like Address 2, which I've never understood anyways.

PS. Poor bug report name. Title the stuff better next time, so people like me can find the bugs easier.

pathfinderelite’s picture

Title: Street 'Additional' field is too smart for its own good » Street 'Additional' field improperly displayed above 'Street' field

You make a good point about what the author wanted. However, this isn't a problem concerning when the additional field is displayed; its about where. The 'Additional' form field needs to be displayed below the 'Street' field on edit forms. I'm sorry if the bug report name was confusing.

vesapalmu’s picture

I had the same problem, issue was fixed with j0rd's fix. Thanks.

j0rd’s picture

No problem. It would be nice if we could get this fix into the next release. I wonder what a dude needs to do, to get some CVS dudes in here.

jenlampton’s picture

Title: Street 'Additional' field improperly displayed above 'Street' field » Street 'Additional' field using only display setings for 'Street location'
StatusFileSize
new756 bytes

I see two different issues here...

The 'Additional' field IS or IS NOT displayed based on the setings for 'Street location'
The 'Additional' field always uses WEIGHT of 'Street location' field

The fix above solves the problem of Additional being added based on only the settings for Street location, but the Additional field still inherits the weight of the Street location field instead of retaining it's own. If the two weights are equal, Additional will come first (alphabetically). Updating the line that sets Additional's weight to that of street solved this other problem for me too.

Original code...

      // Only include 'Street Additional' if 'Street' is 'allowed' or 'required'
      if ($field == 'street' && $fsettings[$field]['collect']) {
        $element['additional'] = location_invoke_locationapi($defaults['additional'], 'field_expand', 'additional', 1, $defaults);
        $element['additional']['#weight'] = (int)$fsettings[$field]['weight'];
      }

My new code...

      // Only include 'Street Additional' if 'Street' is 'allowed' or 'required'
      if ($field == 'street' && $fsettings[$field]['collect'] && $fsettings['additional']['collect']) {
        $element['additional'] = location_invoke_locationapi($defaults['additional'], 'field_expand', 'additional', 1, $defaults);
        $element['additional']['#weight'] = (int)$fsettings['additional']['weight'];
      }

patch attached.

dragonwize’s picture

Status: Needs review » Closed (duplicate)
jenlampton’s picture

Version: 5.x-3.0 » 6.x-3.x-dev
Status: Closed (duplicate) » Needs review
StatusFileSize
new12.41 KB

Just found the same bug in the D6 branch... here's the patch for that.

dragonwize’s picture

Status: Needs review » Closed (duplicate)

The fix was already applied to both branches.

drupalfan2’s picture

This problem still exists in the actual recommended release! Its about a year ago you fixed the problem, but still in stable version.

Please give us 6.x-3.1 to download!

kirikintha’s picture

Issue tags: +location, +Additional, +Form Weight

This is actually fixed, but in an unexpected way.

I had to set the weight of everything like this:

Name Weight
Location name -100
Street location -99
Additional -98
City -97
State/Province -96
Postal code -95
Country -94
Phone number -93

And that seemed to make the form play nice. :)

-k

greenbeans’s picture

The problem addressed by the patch in #3 is persisting for me in 6.x-3.1rc1.