You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a timefield not in html5, when you enter a partial value (10:00) it will fail because it doesn't match the format (hh:mm:ss)... but that's also kind of too strict
I would suggest to expand value as needed (expand 10:00 to 10:00:00) if the input is smaller than the pattern
Additional context or points of discussion
Here is an example of what I did in my own class. Side benefit : no need to have a distinct handling of html5 vs non html5 inputs, they are all treated equal.
/** * Convert frontend time to the internal representation (ISO 8601). * The frontend time is also in ISO 8601 when $html5=true. * * @param string $time * @return ?string The formatted time, or null if not a valid time */protectedfunctionfrontendToInternal($time)
{
if (!$time) {
returnnull;
}
$fromFormatter = $this->getFrontendFormatter();
$toFormatter = $this->getInternalFormatter();
// Expand time as needed by increment of 3 using :00$patternLength = strlen($fromFormatter->getPattern());
while (strlen($time) < $patternLength) {
$time .= ":00";
}
$timestamp = $fromFormatter->parse($time);
// If timestamp still can't be detected, we've got an invalid timeif ($timestamp === false) {
returnnull;
}
return$toFormatter->format($timestamp);
}
Description
Not technically a bug, but still annoying...
When using a timefield not in html5, when you enter a partial value (10:00) it will fail because it doesn't match the format (hh:mm:ss)... but that's also kind of too strict
I would suggest to expand value as needed (expand 10:00 to 10:00:00) if the input is smaller than the pattern
Additional context or points of discussion
Here is an example of what I did in my own class. Side benefit : no need to have a distinct handling of html5 vs non html5 inputs, they are all treated equal.
Validations
PRs
The text was updated successfully, but these errors were encountered: