Symfony 2 - 输入文本输入表单提交

时间:2014-08-08 20:57:00

标签: php forms symfony

如何在下面的文本字段中输入后设置此简单表单?

public function indexAction(Request $request)
{
    // create a task and give it some dummy data for this example
    $task = new Task();
    $task->setTask('test');
    $task->setDueDate(new \DateTime('tomorrow'));

    $form = $this->createFormBuilder($task)
        ->add('task', 'text', array('label' => 'Enter State', 'attr' => array('class' => 'typeahead')))
        ->getForm();

1 个答案:

答案 0 :(得分:1)

我担心Symfony没有选择权 http://symfony.com/doc/current/reference/forms/types/text.html

您总是可以在视图中添加一些JS代码来处理这个问题:

document.getElementById("text_field_id").addEventListener("keydown", function(e) {
    if (!e) { var e = window.event; }
    e.preventDefault();

    // Enter is pressed
    if (e.keyCode == 13) { submitForm(); }
}, false);