[英]Symfony 2 - Form submission on enter in text input
How to I setup this simple form to submit after an enter occurs in the text field below? 在下面的文本字段中输入回车后,如何设置此简单表单以提交?
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();
I'm afraid there is no option for that in Symfony http://symfony.com/doc/current/reference/forms/types/text.html 恐怕Symfony http://symfony.com/doc/current/reference/forms/types/text.html中没有其他选择
You could always add some JS code to your view to handle this: 您总是可以在视图中添加一些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.