簡體   English   中英

Symfony 2-在文本輸入中輸入表單

[英]Symfony 2 - Form submission on enter in text input

在下面的文本字段中輸入回車后,如何設置此簡單表單以提交?

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();

恐怕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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM