添加onkeyup=";countChar(this)“;文本区域表单Symfony 5

添加onkeyup=";countChar(this)“;文本区域表单Symfony 5,symfony,Symfony,在FormType中,我有这个 ->add('message', TextareaType::class, [ 'label' => 'form.input.message', 'help' => 'form.input.help.message' ]) 在index.html.twig中 <div class="form-group"> {{ form_label(form.message) }} <div class=

在FormType中,我有这个

->add('message', TextareaType::class, [
      'label' => 'form.input.message',
      'help' => 'form.input.help.message'
])
在index.html.twig中

<div class="form-group">
   {{ form_label(form.message) }}
   <div class="input-group mb-2 mr-sm-2">
       { form_widget(form.message) }}
   </div>
</div>

{{form_标签(form.message)}
{form_小部件(form.message)}
如何在此文本区域中添加onkeyup=“countChar(this)”

要获得:

<textarea id="thanks_message" onkeyup="countChar(this)" name="thanks[message]" class="form-control" required="required"></textarea>

这些文档对我来说就像你可以做到的那样:

->add('message', TextareaType::class, [
      'attr' => ['onkeyup' => 'countChar(this)'],
      'label' => 'form.input.message',
      'help' => 'form.input.help.message'
]);

或者,您可以使用javascript处理该元素上的keyup事件