Problem/Motivation

The classes applied to fields follow this pattern: field-type-[type] and field-name-[name]

This allows a theme to easily style a particular field or to style a particular type of field.

Unfortunately, the node edit form uses the exact same class names for the field form widgets. Completely different HTML (rendered field vs. form widget), but the exact same class. This is super problematic as any moderately complex field styling can break the corresponding field widget when adding or editing a node.

The classes on the node edit form's field widget containers are to "aid in theming", but they do the opposite. In order to style the field widgets, you first have to undo the styling for the rendered field and then apply the desired widget styling. Even if you don't want special widget styling, you still have to undo the rendered field styling. :-p

Proposed resolution

Change the classes used on the field widget containers created in field_default_form(). There's no reason to use the same class. The easiest way is to prepend form- to the class names, so on the node edit form, they'd be: form-field-type-[type] and form-field-name-[name].

API changes

This will change the class names on field widget containers. But that's the point. They are currently "broken" by anyone's definition.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin’s picture

Status: Active » Needs review
FileSize
1.06 KB

Also, "field-label" is used for the rendered field label and for the field widget's label.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me.

Dries’s picture

Would "form-" work, or does that clash with other classes?

yched’s picture

Works for me too.

@Dries, the patch does 'form-field-type-FIELDTYPE' and 'form-field-name-FIELDNAME', so I don't think I get your proposal.

(Although, for consistency I'd move the classname representing the widget type to 'form-' too)

Jacine’s picture

I support this. It's definitely broken right now and the proposed fix looks reasonable to me.

Jacine’s picture

Component: field system » CSS
sun’s picture

Status: Reviewed & tested by the community » Needs work

I'm heavily confused by the repetition of "node" in this issue - whereas the patch changes CSS classes for all field widgets everywhere.

Can we get a better title?

for consistency I'd move the classname representing the widget type to 'form-' too

I agree with that.

Additionally, I believe that almost everywhere we're using "form" in classes, it is a suffix, not a prefix.

At least, "field-hubba-bubba-form" sounds more natural to me than "form-field-hubba-bubba".

sun’s picture

Issue summary: View changes

Added note about API changes and expanded the problem definition.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: 1245218-1-field-form-bleeding.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: 1245218-1-field-form-bleeding.patch, failed testing.

markconroy’s picture

Adding new patch which I think sorts this.

Sample classes before and after:

frontend (before patch)
field field-node--field-test-text-field field-name-field-test-text-field field-type-string-long field-label-above quickedit-field

frontend (after patch) - no change
field field-node--field-test-text-field field-name-field-test-text-field field-type-string-long field-label-above quickedit-field

backend (before patch)
field-type-string-long field-name-field-test-text-field field-widget-string-textarea form-wrapper

backend (after patch) - has form- class
form-field-type-string-long form-field-name-field-test-text-field field-widget-string-textarea form-wrapper

markconroy’s picture

Status: Needs work » Needs review
andypost’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markconroy’s picture

Status: Needs review » Fixed

Closing this as fixed. Backend form elements are outputting classes like the following, which seems to solve the issue.

js-form-item form-item js-form-type-tel form-type-tel js-form-item-field-fax-number-0-value form-item-field-fax-number-0-value

Status: Fixed » Closed (fixed)

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

Pol’s picture

Version: 8.2.x-dev » 7.x-dev

I think we should backport this to Drupal 7 as well.

Pol’s picture

FileSize
1.27 KB

Here's the D7 patch.

andypost’s picture

Version: 7.x-dev » 8.2.x-dev

@Pol better to file separate issue for D7 - this way it supposed to work now

Pol’s picture

You're absolutely right, sorry for the noise!