-
|
I have an input field in the frontend that renders a datepicker: <input type="text" name="date">I want to map this value to The issue is that when the HTTP request is submitted via ''|\DateTimeImmutableinstead of: null|\DateTimeImmutableIs there a good solution that would allow me to use I tried creating a custom constructor, but this syntax was not allowed: registerConstructor(function (string $value): \DateTimeImmutable|null {
if (empty($value)) {
return null;
}
return DateUtils::parseDate($value);
});This results in the following error: My current solution is to force null or the value inside the method like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Maybe what iam looking for is EDIT: ->registerConverter(function (string $value): \DateTimeImmutable|null {
if ($value === '') {
return null;
}
return DateUtils::parseDate($value);
})
->registerConverter(function (string $value): int|null {
if ($value === '') {
return null;
}
return (int) $value;
}) |
Beta Was this translation helpful? Give feedback.
Hi @eigan, converters are indeed the proper solution. You can use it this way:
Hope this solves your issue 😊