Skip to content

Commit 3c3b77c

Browse files
committed
FIX Only show DatetimeField format description for non-HTML5 inputs
When using HTML5 datetime-local inputs (the default), the scaffolded description shows an ISO 8601 format example that doesn't match what browsers actually display in their native date/time pickers. Fixes #11867
1 parent 710f00b commit 3c3b77c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/ORM/FieldType/DBDatetime.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ public function scaffoldFormField($title = null, $params = null)
182182
$dateTimeFormat = $field->getDatetimeFormat();
183183
$locale = $field->getLocale();
184184

185-
// Set date formatting hints and example
186-
$date = static::now()->Format($dateTimeFormat, $locale);
187-
$field
188-
->setDescription(_t(
185+
// Set date formatting hints and example when not using HTML5 inputs,
186+
// as browsers handle format display natively for HTML5 datetime-local fields
187+
$field->setAttribute('placeholder', $dateTimeFormat);
188+
if (!$field->getHTML5()) {
189+
$date = static::now()->Format($dateTimeFormat, $locale);
190+
$field->setDescription(_t(
189191
'SilverStripe\\Forms\\FormField.EXAMPLE',
190192
'e.g. {format}',
191193
'Example format',
192194
['format' => $date]
193-
))
194-
->setAttribute('placeholder', $dateTimeFormat);
195+
));
196+
}
195197

196198
return $field;
197199
}

0 commit comments

Comments
 (0)