-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fix Date\TimeType marked as invalid on request with single_text and zero seconds #20307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bf6979b
6f26d21
11f6502
4adaa2a
006f236
ea9567e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ext and zero seconds (LuisDeimos)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
namespace Symfony\Component\Form\Extension\Core\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\ReversedTransformer; | ||
|
@@ -49,6 +51,19 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
|
||
if ('single_text' === $options['widget']) { | ||
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format)); | ||
|
||
// handle seconds ignored by user's browser when with_seconds enabled and seconds is 00 | ||
if ($options['with_seconds']) { | ||
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $e) { | ||
if ($data = $e->getData()) { | ||
if (preg_match('/^\d{2}:\d{2}$/', $data)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented suggestions, has not simplified the condition 'if ($ options [' with_seconds '])' to avoid adding an not necessary listener |
||
$e->setData($data.':00'); | ||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
} else { | ||
$hourOptions = $minuteOptions = $secondOptions = array( | ||
'error_bubbling' => true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a link to some issue(s) here, ie the chromium one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can leave out
and seconds is 00
(actually seconds are omitted which you already mentioned).