如何在下面的文本字段中输入后设置此简单表单?
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();
答案 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);