Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DateTimeType HTML5 Chrome #22063

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

Closed
ricardosaracino opened this issue Mar 20, 2017 · 2 comments
Closed

DateTimeType HTML5 Chrome #22063

ricardosaracino opened this issue Mar 20, 2017 · 2 comments

Comments

@ricardosaracino
Copy link

Q A
Bug report? yes
@ricardosaracino
Copy link
Author

ricardosaracino commented Mar 20, 2017

Well i had to do a bit of work to get it working on chrome, not sure what the current html spec says but the my date time would not use the supplied value unless i used my HTML5_FORMAT

{% block date_time_widget %}
	{{ form_widget(form, { 'type' : 'datetime-local'}) }}
{% endblock %}
/**
 * Class UserDateTimeType
 * @package AppBundle\Form\Type
 * 
 * Symfony DateTimeType would not render correctly
 */
class UserDateTimeType extends TextType {

	/**
	 * Works in Chrome
	 */
	const HTML5_FORMAT = 'Y-m-d\Th:i';

	/**
	 * @var \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage
	 */
	private $tokenStorage;

	/**
	 * @param TokenStorage $tokenStorage
	 */
	public function __construct(TokenStorage $tokenStorage)
	{
		$this->tokenStorage = $tokenStorage;
	}

	/**
	 * {@inheritdoc}
	 */
	public function buildForm(FormBuilderInterface $builder, array $options)
	{
		$builder->addModelTransformer(new \AppBundle\Form\Transformer\UserDateTimeTransformer($options['model_timezone'], $options['view_timezone'], $options['format']));
	}

	/**
	 * {@inheritdoc}
	 */
	public function configureOptions(OptionsResolver $resolver)
	{
		$resolver->setDefaults(
			[
				'widget' => 'single_text',
				'compound' => false,
				'input' => 'sting',
				## UserDateTimeTransformer
				'format' => self::HTML5_FORMAT,
				'model_timezone' => 'UTC',
				'view_timezone' => $this->tokenStorage->getToken()->getUser()->getTimeZone(),
			]
		);
	}

	/**
	 * @return null|string
	 */
	public function getBlockPrefix()
	{
		return 'date_time';
	}
}

http://imgur.com/QHYdnjf

@xabbuh
Copy link
Member

xabbuh commented Sep 14, 2018

This looks like the same as #27233 for me which has a pending pull request. So I am going to close here.

@ricardosaracino Can you confirm that #28372 fixes your issue too?

@xabbuh xabbuh closed this as completed Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants