Symfony 2.8 Forms / Twig: Twig doesn't display my input correctly (type = date)

I expect that when the page is displayed, it will be entered (type = date). But I get type = text.

<html>
    <head></head>
    <body>
        <input id="test_form_studentdob" class="normal" type="text" placeholder="DD-MM-YYYY" name="test_form[studentdob]">
    </body>
</html>

I already tried this:

  • multiple browsers (both desktop and mobile)

  • removed all CSS / JS that I loaded inside. This includes loading the jQuery / jQuery / bootstrap user interface libraries

Any ideas what I can do wrong? thank

Symfony controller fragment:

/**
 * @Route("/test")
 */
public function testAction(Request $request) {
    $form = $this->createForm(new TestFormType());
    $form->handleRequest($request);

    return $this->render(
        "AppBundle:SelfService:TestForm.html.twig"
        , array("form" => $form->createView())
    );
}

Symfony Form Type Type:

<?php
// src/appBundle/Form/TestFormType.php
namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType
    , Symfony\Component\Form\FormBuilderInterface
    , Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TestFormType extends AbstractType {
    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(
            array(
                "attr" => array(
                        "id" => "testform"
                )
            )
        );
    }

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
            ->setMethod("GET")
            ->add(
                "studentdob"
                , "date"
                , array(
                    "attr" => array(
                        "class" => "normal"
                        , "placeholder" => "DD-MM-YYYY"
                    )
                    , "format" => "dd-MM-yyyy"
                    , "required" => false
                    , "widget" => "single_text"
                )
            );
    }
}

This is my Twig template:

{% block body %}
    {{ form_widget(form.studentdob) }}
{% endblock %}
+4
source share
1 answer

HTML date input has a unique format: yyyy-mm-dd

, RFC 3339, , 0.

, .

Symfony , .

+2

Source: https://habr.com/ru/post/1650776/


All Articles