The field label doesn't appear if enabled "Render as a regular field" option and the attributes to collect were only "Year"

Comments

mqanneh’s picture

Status: Active » Needs work
StatusFileSize
new676 bytes
mqanneh’s picture

Status: Needs work » Needs review
mqanneh’s picture

Priority: Normal » Major
joelstein’s picture

Component: Code » User interface
StatusFileSize
new638.99 KB
new699.57 KB
new657.65 KB
new717 bytes

I'm experiencing the same problem. The "Render as a regular field " works flawlessly except for "Select list" field widgets with only one value (year).

To test this out, I created a whole bunch of combinations of date fields, in the fieldset, as a normal field, and with the popup, select, and text widgets. See the first image to see the broken select labels when only the year field is used.

The patch mqanneh provided fixes that use case, but it breaks rendering for "Text field" widgets when rendering as a regular field. See the next attached image to see the duplicate text field labels with mqanneh's patch.

I did a bunch of testing, and it looks like the code in date.theme that hides the #title_display should only be called if using the text field widget. By restricting that code to the text field widget, it won't break anything for select list fields. See the last attached image to see the select labels fixed, and everything else rendering as expected. The attached patch accomplishes this.

(As an aside, I think it's strange that we give users the option to configured a field with "labels above" for text field widgets, since they never appear. Just a minor usability issue I noticed while researching this.)

joelstein’s picture

Status: Needs review » Needs work

Rats, just discovered that my patch breaks Popup fields with date only fields (no time fields).

Back to the drawing board.

abu-zakham’s picture

Status: Needs work » Reviewed & tested by the community

Patch #1 works fine with me, thank you @mqanneh.

abu-zakham’s picture

Status: Reviewed & tested by the community » Needs work

You are right joelstein. in comment #5 , patch #1 and patch #4 breaks Popup fields with date only fields (no time fields).

bjcooper’s picture

Status: Needs work » Needs review

Can we just check for date popup as well (date.theme line 460)?

-  // Detect if there is more than one subfield.
-  $count = count(explode('<label', $element['#children'])) - 1;
-  if ($count == 1) {
-    $element['#title_display'] = 'none';
-  }
+  // For text and popup widgets, hide the title if there is only one subfield.
+  if (in_array($element['value']['#type'], array('date_text', 'date_popup'))) {
+    $count = count(explode('<label', $element['#children'])) - 1;
+    if ($count == 1) {
+      $element['#title_display'] = 'none';
+    }
+  }
damienmckenna’s picture

Assigned: mqanneh » Unassigned

Reminder: the "assigned" field is for indicating that you are actively working on something, it is not for indicating that you reported a problem or that you previously worked on a problem and would like attribution. Thanks.

aurelianzaha’s picture

StatusFileSize
new946 bytes

Hi,

I had a bit different issue, but the attached patch might solve the original problem as well.
The issue that I had is that the label of the main field was not rendering when granularity of date only was selected, although the 'Position of date part labels' was none.