- Issue created by @apiddington
- ๐บ๐ธUnited States Scott Weston
Tested with the latest Drupal Version 9.2.0-dev using MacOS Safari. The patch does resolve the error displaying:
Before patch
Without patch applied, using a placeholder on a date field causes an error
After patch
After applying the patch, using a placehodler on a date field does not cause an error
For this, marking as RTBC.
It's worth noting that Desktop Chrome and Desktop Firefox both override date fields to use the browser's datepicker. To override this behavior, the following guidance is given: http://trac.webkit.org/wiki/Styling%20Form%20Controls#Dateinputtype. Mobile browsers generally use the mobile OS's datepicker.
- ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
Thanks, as this is a bug, we need a test to demonstrate that it's fixed
- ๐ฎ๐ณIndia raman.b Delhi
As suggested by #5,
It's worth noting that Desktop Chrome and Desktop Firefox both override date fields to use the browser's datepicker. To override this behavior, the following guidance is given: http://trac.webkit.org/wiki/Styling%20Form%20Controls#Dateinputtype. Mobile browsers generally use the mobile OS's datepicker.
Since the test bot uses chrome web driver, I'm not sure if we can test the placeholder value for the date element. Attaching a failing test nevertheless
The last submitted patch, 7: 3189302-7-test-only.patch, failed testing. View results โ
- ๐ง๐ทBrazil renatog Campinas
This is a long line
foreach (['textfield', 'textarea', 'url', 'password', 'search', 'tel', 'email', 'number', 'date'] as $type) {
Please could you define an array in a line and after that use the "foreach" in another one? E.g.:
$fieldTypes = [ 'textfield', 'textarea', 'url', 'password', 'search', 'tel', 'email', 'number', 'date' ]; foreach ($fieldTypes as $type) { $form[$type] = [ '#type' => $type, '#title' => $type, '#attributes' => ['placeholder' => 'placeholder-text'], ]; }
- ๐ช๐จEcuador jwilson3
The issue summary states:
$form['date1'] = array( '#type' => 'date', '#title' => t('Date'), ); $form['date2'] = array( '#type' => 'date', '#attributes' => array('placeholder' => 'yyyy-mm-dd'), '#title' => t('Date placeholder'), );
The undefined index notice is raised for date2, but not date1.
However, I'm seeing this issue on enabling the styleguide module, which doesn't contain an '#attributes' array key at all.
$form['date'] = [ '#type' => 'date', '#title' => $this->t('Date'), '#description' => $this->generator->sentence(), ];
The patch does work to correct the issue, however, (and I hate to do this) but in reading through the code and the patch in #11, I'm getting the feeling this patch is actually just covering up a deeper issue which is slightly unintuitive. The Date.php file the patch acts on contains two pertinent methods, a processDate() function and a preRenderDate(). If I understand correctly, these map to the #process and #pre_render functions from Form API. I think #process functions run before #pre_render, therefore it seems backward that in the #pre_render function there is code that adds
$element['#attributes']['type'] = 'date';
, and in the #process the code (as currently written without the patch) assumes that $element['#attributes']['type'] would be set.Therefore, my question is, could the if statement just be simplified from:
if ($element['#attributes']['type'] == 'date' && !empty($element['#date_date_format'])) { $element['#attached']['library'][] = 'core/drupal.date'; $element['#attributes']['data-drupal-date-format'] = [$element['#date_date_format']]; }
to:
if (!empty($element['#date_date_format'])) { $element['#attached']['library'][] = 'core/drupal.date'; $element['#attributes']['data-drupal-date-format'] = [$element['#date_date_format']]; }
My apologies if this is misguided.
- ๐ช๐จEcuador jwilson3
It seems like this exact same issue was filed 6 years ago #2528482: Fix notice in Date::processDate โ with commit 9f6d914. And it didnt solve the problem.
Drupal 9.3.15 โ was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule โ and the Allowed changes during the Drupal core release cycle โ .
Drupal 9.1.10 โ (June 4, 2021) and Drupal 9.2.10 โ (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule โ and the Allowed changes during the Drupal core release cycle โ .
- ๐ช๐จEcuador jwilson3
Adding a few more related core issues:
- #3189325: Undefined index: type in Drupal\Core\Render\Element\Date::processDate() โ closed as a duplicate of this issue
- ๐ Date field doesn't allow attributes Needs work
- #3144876: PHP Notice: Undefined index: type in claro_preprocess_input() (line 680 of core/themes/claro/claro.theme) โ
And some contrib module issues have had to work around this with several patches:
- Date Popup: #2983674: Date attribute is missing โ and followup #3042555: Notice: Undefined index: type in Drupal\Core\Render\Element\Date::processDate() โ
- Search API Date Popup: #3115384: Notice: Undefined index: type โ
- ๐ช๐ธSpain jmohino
Hi all!! I was using this patch (3189302_11.patch) until version 9.3.16 without problems, when updating to version 9.4.1, I get the following error:
Revisando el parche core/lib/Drupal/Core/Render/Element/Date.php... error: mientras se busca: public static function processDate(&$element, FormStateInterface $form_state, &$complete_form) { // Attach JS support for the date field, if we can determine which date // format should be used. if ($element['#attributes']['type'] == 'date' && !empty($element['#date_date_format'])) { $element['#attached']['library'][] = 'core/drupal.date'; $element['#attributes']['data-drupal-date-format'] = [$element['#date_date_format']]; } error: el parche fallรณ: core/lib/Drupal/Core/Render/Element/Date.php:62 error: core/lib/Drupal/Core/Render/Element/Date.php: el parche no aplica Revisando el parche core/modules/system/tests/modules/form_test/src/Form/FormTestPlaceholderForm.php...
- ๐ช๐ธSpain jmohino
Many thanks Ranjith_kumar!! 3189302-18.patch works for me.
- ๐ฎ๐ณIndia gayatri chahar
I checked #18 patch against 9.4.x and its working form me
Thanks @ranjith_kumar_k_u - ๐ช๐จEcuador jwilson3
- ๐ง๐ชBelgium BramDriesen Belgium ๐ง๐ช
The patch solves the notice. Status is indeed need work for #12 / #21
- ๐ฎ๐ณIndia ankitsingh0188 Pune
Patch #24 ๐ Notice: Undefined index: type in Drupal\Core\Render\Element\Date::processDate() Closed: outdated applied successfully. I have tested the patch and it works for me.
I have attached the screenshot before_patch.png in which I am getting the notice and it disappears after I applied the patch.
Looks good to me! Good to move it to RTBC.
if (!empty($element['#attributes']['type']) && $element['#attributes']['type'] == 'date' && !empty($element['#date_date_format'])) {This works
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
The patch does not apply on 10.1.x/10.0.x - even with a 3way merge so we need an patch for 10.x
Drupal 9.5.0-beta2 โ and Drupal 10.0.0-beta2 โ were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule โ and the Allowed changes during the Drupal core release cycle โ .
@alexpott,
+++ b/core/lib/Drupal/Core/Render/Element/Date.php +++ b/core/lib/Drupal/Core/Render/Element/Date.php @@ -68,7 +68,7 @@ public static function processDate(&$element, FormStateInterface $form_state, &$
processDate
method doesn't exist incore/lib/Drupal/Core/Render/Element/Date.php
class in Drupal 10.x.This is removed in Deprecate core/drupal.date asset library in 9.4.0 โ
do we need the reroll of patch #24 without
core/lib/Drupal/Core/Render/Element/Date.php
this file changes?- ๐ฎ๐ณIndia sahil.goyal
reroll the patch #24 for the version 10.1.x-dev and as per the comment of @ravi.shankar processDate method doesn't exist in core/lib/Drupal/Core/Render/Element/Date.php class in Drupal 10.x. so the date condition cannot be apply so the rerolled patch can be apply to the 10.1.x version.
Drupal core is moving towards using a โmainโ branch. As an interim step, a new 11.x branch has been opened โ , as Drupal.org infrastructure cannot currently fully support a branch named
main
. New developments and disruptive changes should now be targeted for the11.x
branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule โ and the Allowed changes during the Drupal core release cycle โ .- ๐บ๐ธUnited States smustgrave
Patch #33 just includes a test change but if we aren't fixing anything I doubt it's needed.
So question is do we close this as outdated as it may not be needed for D10?
Keep for D9.5? - Status changed to Closed: outdated
about 1 year ago 2:50pm 13 November 2023 - ๐ง๐ชBelgium borisson_ Mechelen, ๐ง๐ช
This was fixed when the method was deprecated/removed from drupal 10. I think we can safely close this issue as outdated.