Problem/Motivation

Datetime element support for #suffix key leads to #suffix being duplicate. Once after date and once after time.

Ex.:

$form['datetime'] = [
  '#type' => 'datetime',
  '#default_value' => date('Y-m-d H:i:s'),
  '#ajax' => array(
    'callback' => array($callback_object, 'datetimeCallback'),
  ),
  '#suffix' => '<div id="ajax_datetime_value">No datetime yet selected</div>',
];

Results in :

Proposed resolution

Insert #prefix part before datetime, and #suffix part after it.

User interface changes

#prefix and #suffix should appear once only.

API changes

None

Comments

Dom. created an issue. See original summary.

dom.’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new535 bytes
new3.54 KB

Patch attached.

Before patch screenshot is in issue summary.

After screenshot:

mpdonadio’s picture

Issue tags: +Needs tests

Thanks for working out all of these datetime related FAPI bugs.

Think we need a test here to make sure the #prefix and #suffix appear exactly once to prevent a regression if we rework the wrapper (eg, #1918994: Improve Datetime and Daterange Widget accessibility).

I am also scratching my head here. Not seeing similar unsets for other form elements that have wrappers? What is different about this one?

mpdonadio’s picture

Status: Needs review » Needs work

Spent some time looking at this one. Did some testing with other form and render elements that have wrappers (mainly looked at checkboxes and dropbuttons).

The other elements seem to build up the wrapped contents individually, while this has a blind

$variables['content'] = $element;

in template_preprocess_datetime_form(), which is what is causing the double prefix/suffix. The render engine handling those directly, but the other elements that would be duplicated (like #title) are handled by the templates themselves. So, I think this fix does look like it is correct.

Setting NW, because I think this needs a test to show the problem and to prevent a regression. Test should cover both 'datetime' and 'datelist' elements (it happens with both), that the '#prefix' and '#suffix' appear exactly once. Should also probably test that the '#prefix' and '#suffix' are the the right places.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

dom.’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.9 KB
new3.38 KB
new3.68 KB

Here are new patchs containing test (and test-only version).
It check the presence of only one suffix and prefix for both date and datetime elements.
NOTE: the issue occurs only with datetime element, not simple date.

The full patch also includes correction.

The patch is design to merge with : #2782831: Date FAPI element type do not support #attributes meaning that the test form and DateTest file are the same in both.

Status: Needs review » Needs work

The last submitted patch, 6: avoid_duplicate_prefix_suffix--2783617-6--tests-only.patch, failed testing.

dom.’s picture

Status: Needs work » Needs review

Back to "need review" : test--only fails as expected, full patch is successfull at test-bot !

dom.’s picture

Issue tags: +DevDaysSeville

Adding issue tag, hoping for review :)

haza’s picture

Issue summary: View changes
StatusFileSize
new3.62 KB

Tested the patch, and I can confirm it is working as expected.

On a side note, if we use a #prefix and a #title in the datetime element, the title is set to be inline.

No sure if we need to deal with that here. (I guess, no)

Status: Needs review » Needs work

The last submitted patch, 6: avoid_duplicate_prefix_suffix--2783617-6--tests-only.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

k4v’s picture

Status: Needs work » Reviewed & tested by the community

Works for me too.

xjm’s picture

Hm the bug is pretty clear but a bugfix that relies on an unset in a preprocess to work around code elsewhere seems... wrong. Since I don't have an actionable suggestion on what else to do I'll ping the frontend framework managers here to see what the think. Thanks!

xjm’s picture

Actually, inaugurating a new tag.

mpdonadio’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.86 KB
new4.39 KB
new1.61 KB

We need to also add test coverage for the 'datelist' element, too, since that is affected.

The last submitted patch, 16: 2783617-16-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tacituseu’s picture

@frontend framework manager:
I feel like this and other issues with complex (multi element/input) widgets stem from lack of generic way of dealing with them in core, which results in:
- custom '#theme_wrapper's ('datetime_wrapper', 'checkboxes', 'radios')
- nested '.form-item's and '.form-wrapper's
- changing structure issues (label and description sometime inside 'form-item', sometimes outside)

Tried looking for some clear definition of what exactly '.form-item' and '.form-wrapper' is without any luck.

Shouldn't there be one more level to all of this like '.form-element' (or '.form-input') ?
So it would become '.form-item > .form-element > input', and there can be multiple '.form-element's inside '.form-item', and multiple 'input's inside '.form-element', but never nested '.form-item's or '.form-element's.

tacituseu’s picture

Noticed there's also CompositeFormElementTrait with '.form-composite', so I guess it's meant to be '.form-composite > .form-item > input'.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

lauriii’s picture

lauriii’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2346893: Duplicate AJAX wrapper around a file field

Seems like the test only patch is now passing. Marking as a duplicate for #2346893: Duplicate AJAX wrapper around a file field.

lauriii’s picture