Updated: Comment #5

Instructions to reproduce the problem

  1. Enable date_repeat_field module.
  2. Create a date field to a content type.
  3. Add something to the "Help text" field in the field creation form.
  4. Set the "Repeating date" to "No".
  5. Check that help text is shown on the node create/edit form for the date field.
  6. Set the date field's "Repeating date" to "Yes".
  7. Check the node create/edit form. Now the help text is missing.

Diagnosis

Drupal's core field module handles multivalue fields differently than single value fields. Help text is not positioned after every field instance but below the set of fields. Date repeat field is a multivalue field. For multivalue fields the help text (description) is removed and printed separately. The problem seems to be that date_repeat_field module does not use the function theme_field_multiple_value_form to render the field set and doesn't render it. Below is the relevant code.

Drupal 7.26 - /modules/field/field.form.inc
function field_multiple_value_form
Line 218: '#description' => $multiple ? '' : $description,
Removes the help text from single field instances.

function theme_field_multiple_value_form
Line 350: $output .= $element['#description'] ? '

' . $element['#description'] . '

' : '';
Adds help text below multivalue fields. This function is not used by date_repeat_field.

See also:

Proposed resolution

Let's find out where the date repeat field is rendered and add the description tag there. Positioning it at the top would probably be best.

Remaining tasks

  • Find out where the date repeat field is rendered.
  • Add the help text element (description) to date repeat field.

User interface changes

  • Help text is displayed also with the repeat option on.

API changes

None.

Comments

vijaycs85’s picture

Thanks for reporting @jiv_e. I can reproduce the issue and at first look I thought might be introduced by #1691342: field description is displayed multiple times. But it is not. However I couldn't really get the bottom of it.

jiv_e’s picture

Assigned: Unassigned » jiv_e

Working on it.

jiv_e’s picture

Issue summary: View changes

Updated the issue summary.

jiv_e’s picture

Issue summary: View changes

Fixed typos.

jiv_e’s picture

Issue summary: View changes
StatusFileSize
new3.22 KB

Here's a patch. It does the following:

  1. Uses fieldset description for date combo elements e.g. date repeat fields. This means that the help text is displayed at the top of the fieldset. This prevents the help text to be pushed down when the fieldset is expanded. Current code implies that in some cases fieldset description is used, but it didn't work.
  2. This touches other fieldsets also, but it's good because now the date combo elements have unified look.
  3. Simplifies code by removing unnecessary conditionals and variable names.
jiv_e’s picture

Status: Active » Needs review

Marking as needs review.

vijaycs85’s picture

Thanks for working on this. @jiv_e. Here is some code level comments. Will have a manual check and would be great to have some tests to cover this cases.

  1. +++ b/date.theme
    @@ -374,7 +374,7 @@ function theme_date_combo($variables) {
    -    '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
    +    '#description' => !empty($element['#description']) ? t($element['#description']) : '',
    

    not sure, why can't we keep the field_description here?

  2. +++ b/date_elements.inc
    @@ -331,8 +331,11 @@ function date_combo_element_process($element, &$form_state, $form) {
    -  $description =  !empty($element['#description']) ? t($element['#description']) : '';
    -  unset($element['#description']);
    

    Unset is to avoid duplicate of them, which doesn't looks like covered in this patch anymore

  3. +++ b/date_elements.inc
    @@ -375,8 +378,7 @@ function date_combo_element_process($element, &$form_state, $form) {
    -    $element['#fieldset_description'] = $description;
    +    $element['#description'] .= '<span class="js-hide"> ' . t("Empty 'End date' values will use the 'Start date' values.") . '</span>';
    

    Again, why not fieldset_description?

jiv_e’s picture

Happy to help!

  1. Removing $element['#fieldset_description'] and using just $element['#description'] simplifies the code. It allows us to get rid of $description helper variable. My goal is to use the fieldset description for all date_combo fields. If that's ok we don't need to separate description and fieldset_description anymore.
  2. Because of using fieldset description for all date_combo fields we don't need to unset the $element['#description']. If this is not correct tell me where the dublicate help text can be seen.
  3. See 1. It was only used in date.theme file and my patch removes it from there also. This way we can get rid of it entirely.

I admit that this fix is wider than the original issue, but this fixes the issue and in my opinion unifies the date_combo fields interface and makes the UX better. Otherwise we would have help text at the top of the fieldset for fields with repeat on and bottom of the fieldset for start-end fields only.

vijaycs85’s picture

Issue tags: +sprint
marc.groth’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @jiv_e for the patch. From a functionality perspective it works perfectly. I re-rolled it against 7.x-2.8 to test locally without any issues. Good job :)

Marking it as 'Reviewed & tested by the community' as it's been a year and nobody has said it's a problem.

jiv_e’s picture

Thanks! :)

pmackay’s picture

Would it be possible to get this rolled into a release?

podarok’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

this needs tests coverage

kaare’s picture

StatusFileSize
new2.59 KB
new959 bytes

Patch didn't apply, so re-rolled with minor coding style fixes.

kaare’s picture

Status: Needs work » Needs review
jastraat’s picture

The patch in #14 worked for our purposes.

streever’s picture

It looks like this is fixed & working; can I post here to get an auto notification when the issue is 'resolved' and it's rolled out?
thanks (and apologies if I've done something wrong...!)

jiv_e’s picture

@podarok, can you describe what things should our tests cover?

jiv_e’s picture

Assigned: jiv_e » Unassigned
PascalAnimateur’s picture

Using patch #14 doesn't work with localize_fields.

Here's a simpler patch that does work in my case, but removes the extra text added regarding the start / end components.

merilainen’s picture

StatusFileSize
new2.59 KB

Patch in #20 applied, but didn't help me. I modified the patch in #14 and removed the t() which is not required for field strings, I think they are automatically running through t() anyway. Now it works and I can translate the string normally from Drupal UI.

lussoluca’s picture

StatusFileSize
new2.48 KB

Rerolled #5 on top of the new 2.9 release

WorldFallz’s picture

Title: Date repeat removes the field's help text » missing help text

This also fixes an issue where the help text doesn't display when the "Render as a regular field" option is used on a non-repeating date field.

paulwdru’s picture

Very funny, after applying patch #22, if I tick Render as a Regular Field, both field label and help text can be translated under Node & Entityform but Profile2 shows Untranslated Label with Translated Help Text.

How come only Label is NOT translated in Profile2 ? I'd never encountered situation like this.

Any ideas ? Thanks

paulwdru’s picture

Hi,
Referring to #24, I traced out the cause of why label wasn't translated in Profile2 when using Date-Popup widget.

Could someone create a patch for date/date_popup/date_popup.module at line 326 as follows ?

Original

      $element['date']['#title'] = check_plain($element['#instance']['label']);
      $element['date']['#required'] = $element['#required'];
    }
    elseif (empty($element['date']) && !empty($element['time'])) {
      $element['time']['#title'] = check_plain($element['#instance']['label']);

Changed To

      $element['date']['#title'] = t(check_plain($element['#instance']['label']));
      $element['date']['#required'] = $element['#required'];
    }
    elseif (empty($element['date']) && !empty($element['time'])) {
      $element['time']['#title'] = t(check_plain($element['#instance']['label']));

I'm not familiar with creating a patch and just manually modified the codes.

Thanks

Anonymous’s picture

#22 fixes the missing help problem when displaying as a regular text field

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
autopoietic’s picture

I can confirm that #22 fixes the issue I was experiencing whereby a standard single value date field (in my case on a user profile) was not displaying the configured help text.

zerolab’s picture

Status: Reviewed & tested by the community » Needs work

Nitpicking here, but we need to stick to the d.o. coding standards

  1. +++ b/date_elements.inc
    @@ -337,8 +337,11 @@ function date_combo_element_process($element, &$form_state, $form) {
    +  if(isset($element['show_repeat_settings']) && !empty($element['value']['#instance']['description'])) {
    

    Space after if

  2. +++ b/date_elements.inc
    @@ -337,8 +337,11 @@ function date_combo_element_process($element, &$form_state, $form) {
    +    //Date repeat is a multiple value field. So the description is removed from the
    

    Space after //.
    the goes past the 80 char limit.

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new2.48 KB

Fixes for the minor coding standards mistakes.

zerolab’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

damienmckenna’s picture

idebr’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/date.theme
@@ -402,7 +402,7 @@ function theme_date_combo($variables) {
+    '#description' => !empty($element['#description']) ? t($element['#description']) : '',

The t-function is not necessary: this function should never be used to translate variables. Translating the field description can be be done with i18n_field.

welly’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.47 KB

Updated the patch based on feedback above. Can confirm this is working as expected. Can we get this merged?

damienmckenna’s picture

While you shouldn't mark your own patch as RTBC, the patch looks good and the only change is removal of the t() function.

welly’s picture

Apologies, I thought I'd selected Needs Review! Must have mis-clicked.

  • vijaycs85 committed 5697af7 on 7.x-2.x
    Issue #2186191 by kaare, jiv_e, DamienMcKenna, welly, PascalAnimateur,...
vijaycs85’s picture

Status: Reviewed & tested by the community » Fixed

Only unanswered item is #25 which doesn't look like related to this issue @paulwdru, please check the issue queue for related issue and if not found, create a new issue for the title translation issue you are facing.

Status: Fixed » Closed (fixed)

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