I'm using css to unfloat these fields, but it's impossible to squish the whitespace created by the prefix that's set on certain inline elements (city, state, zip). The margin-right in the addressfield CSS handles the spacing just fine in bartik and seven at the least. Can we remove these prefix settings?

Comments

flortjes’s picture

Note that this would also fix issue #1224562: Theming Address Field form is difficult

David D’s picture

Has this been committed to the current release?

mrfelton’s picture

Status: Needs review » Reviewed & tested by the community

Much better. Thanks.

geerlingguy’s picture

Closed #1224562: Theming Address Field form is difficult and moving my 'follow' over here. Patch is definitely RTBC by me as well. This is quite annoying for those who want vertical alignment of the fields; there is literally no way to adjust spacing in CSS. (Maybe some really hackish ways using line heights and such, but that's just wrong.

damien tournoud’s picture

How does this affect rendering of addresses? (ie. the formatting part?) The renderable array is used for both.

geerlingguy’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.31 KB

Updated patch against latest -dev release (old patch wasn't working).

geerlingguy’s picture

It's for the form, and not the rendered address. For example, if I want to line up the form field elements vertically, strange gaps appear between city/state/zip (american... really locality, province, postal or whatever):

Addressfield form - vertically aligned

See my notes in #1224562: Theming Address Field form is difficult for more.

geerlingguy’s picture

StatusFileSize
new12.28 KB

...and if I apply the patch, then those spaces are gone, meaning I can actually space the form elements myself using CSS - padding, margins, etc. Before, I'd have to adjust line heights in weird ways, or use negative margins to get fields to line up. And I'd have to do that on labels and fields.

Example after patch applied:

Addressfield with patch applied - spaces gone

magicmyth’s picture

I've just run into this issue when styling the forms but it is not something a simple space character should cause so I looked into the code and found the prefixes were not actually using a normal space character but some other funky unicode character. The browsers try to deal with this as best they can and creates a   element which inherits all kinds of styling.

My guess is this is an accident by the author probably from pasting the text from somewhere else and the character not showing in the author's text editor. For example, gedit does not show the character (just white space) but kate does. If you simply delete the character and put in a correct unicode space it should work fine in the browsers (a normal whitespace should not influence block elements nor inherit style).

If you are curious what the character is you can see it mapped in Drupal in the file includes/unicode.entities.inc line 135.

The addressfield author may have done this for a deliberate reason though as it has been used for prefixes throughout (including the name field (name-full.inc) plugin). If so I would like to know the reason?

If this issue is causing you problems and you don't want to edit the modules code you can probably work around it in your theme using either a form alter and editing the prefix or possibly in a pre-process. I've not yet attempted this though.

Hope you find this info useful?

fearlsgroove’s picture

StatusFileSize
new3.26 KB

Attached patch handles the render version better, adds a comma after city for US addresses, and fixes a bug exposed by this change where '#prefix' should have been '#field_prefix', which doubled the prefix value. Tested in garland and a few custom themes. Without additional styling by a theme, things should look identical pre and post patch in both render and form mode, but the prefixes are gone which makes stacked addressfields trivial.

muschpusch’s picture

Sorry really short on time but the patch doesn't fix:

plugins/format/name-full.inc still an ascii something

markabur’s picture

Thanks, #10 works for me to remove the extra space within City - State - Zipcode, and the comma after city is a good change. Tested in an Omega subtheme.

Anonymous’s picture

Thanks for the patch! I can confirm w/ markabur that #10 works. Also tested in an Omega subtheme.

fearlsgroove’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applies, RTBC based on 12/13. Addresses should be visually no different either when rendered or displayed as a form/widget, but should be much easier to style at the theme layer.

pounard’s picture

This patch is missing some occurences, in actual version there are 4 non breakable whitespaces:
in plugins/format/address.inc: lines 61, 88 and 362
in plugins/format/name-full.inc: line 36
(the last one is missing)

henrijs.seso’s picture

Status: Reviewed & tested by the community » Needs work

#10 is mostly good, except this code at the end of address.inc This adds space to postal code that might not be entered in form making space before city in address. There should be check if data exists before inserting prefix.

Patch could be updated with checking not only if mode == render but also if field to be rendered before current field is not empty, this would remove spaces in beginning of address lines.

  if ($context['mode'] == 'render' && !empty($address['postal_code'])) {
    $format['locality_block']['locality']['#prefix'] = ' ';
  }
timodwhit’s picture

Great Patch, helped a lot and made the form so pretty! :-)

Are their plans on rolling this into the next release?

iamEAP’s picture

Status: Needs work » Reviewed & tested by the community

Any chance we can get this committed and create a followup task for mansspams concerns in #16?

I'm utilizing #10 and it works wonderfully.

johnpitcairn’s picture

Ack, yes, can we have this committed please?

milesw’s picture

I can also confirm that #10 solves the extra whitespace issue.

stevieb’s picture

#10 also fixed the issue for me

johnpitcairn’s picture

A word from the module maintainers at this point might be good. About to go live with the patched version here.

What, if anything, is this waiting on? Do we need to roll another patch to address #11/15/16, or can we handle those in a followup?

fearlsgroove’s picture

StatusFileSize
new2.24 KB

This is a re-roll that applies cleanly. @magicmyth also had a good point -- the reason whitespace matters at all here (normally it doesn't) is that the current code is using non-breaking spaces instead of normal spaces. This patch just replaces with normal spaces, which produces the same effect without making it impossible to "unfloat" cleanly.

Also still fixes the double prefix bug -- there's another patch for this here but those patches are wrong as they mix up #prefix and #field_prefix

barraponto’s picture

Works as advertised :)

andyg5000’s picture

#23 Works great for me. Just need to update the space prefix in plugins/format/name-full.inc to fix name form when using separate first and last name fields. Thanks!

barraponto’s picture

@andyg5000 can you elaborate? is there something else that is needed for this patch to be commited?

nelslynn’s picture

Are the spaces (nbsp;'s) going to be removed after the first name, city and state? Spacing should not be included here. It makes for very inflexible styling of an address. Spacing such as this can be accomplished with CSS, and shouldn't be hard coded.

Status regarding this?

fearlsgroove’s picture

StatusFileSize
new2.69 KB

Updating to fix the prefix on last name as well.

andyg5000’s picture

I've had to use this on the past two projects. Please commit :) R&TBTC

k4v’s picture

#28 works for me =)

Loac’s picture

For example, you can use custom module and hook_form_alter().

function tools_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
  unset($form['customer_profile_billing']['commerce_customer_address']['und'][0]['locality_block']['locality']['#prefix']);
  unset($form['customer_profile_billing']['commerce_customer_address']['und'][0]['locality_block']['administrative_area']['#prefix']);
}
chi’s picture

Title: Don't insert a space as prefix for inline elements » Don't insert a strange character as prefix for inline elements

As stated in #9 it isn't a space.

johnv’s picture

Marked these issues as (possible) duplicates:
#1945600: #field_prefix/#prefix behavior broken, inconsistent with #field_suffix/#suffix in rendered addresses
#1410612: Double #prefix problem
#1482802: Prefix Duplication in plugin

Also: this issue started as a 'space' issue, and #10 introduced the 'prefix' issues, which is already treated in the above issues.
Are we sure we aren't discussing 2 different issues?

Garrett Albright’s picture

I started #1945600: #field_prefix/#prefix behavior broken, inconsistent with #field_suffix/#suffix in rendered addresses after encountering the prefix issue which #28 will fix. Would love to see this patch make it into the project. What's the current hold-up? I don't see one on this issue since #28 was posted… I'd be glad to help tackle it.

rszrama’s picture

Title: Don't insert a strange character as prefix for inline elements » Don't duplicate addressfield element prefixes or use non-breaking space prefixes for inline elements
Status: Reviewed & tested by the community » Fixed

Committed #28. I like how this one got sent back to RTBC after being reverted to needs work without the extra work being addressed. : P

In any event, sorry it took so long, and kudos to fearlsgroove for sticking with it long enough to get us to a good patch. Thanks to folks for reviewing and posting the success, too. : )

Commit: http://drupalcode.org/project/addressfield.git/commitdiff/bc78ab0

Status: Fixed » Closed (fixed)

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

aidanlis’s picture

If you want to remove the inline class without touching the styling:

function YOURMODULE_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
  $ele =& $form['customer_profile_billing']['commerce_customer_address']['und'][0];
  unset($ele['name_block']['#attributes']['class'][0]);
  unset($ele['locality_block']['#attributes']['class'][0]);

  // Remove the   (don't use if you're using a version later than bc78ab0)
  unset($ele['name_block']['last_name']['#prefix']);
  unset($ele['locality_block']['locality']['#prefix']);
  unset($ele['locality_block']['administrative_area']['#prefix']);
  unset($ele['locality_block']['postal_code']['#prefix']);
}