0

want to ask for symfony2 form text type, I have two fields to fill in: one is username, the other is email. Code something like:

$builder->add('username', TextType::class)
        ->add('email', TextType::class);

To save effort, I want when the user fills in username, the email will automatically be username@qq.com by default. But the user still can modify email if he wants. How to achieve that in symfony form type? How to modify the FormType class and need to use javascript in html? Thanks!

Kai Huang
  • 73
  • 1
  • 10
  • You want the email to be filled at the very moment the username is typed in? Then it is a JavaScript question and actually unrealted to Symfony, as the backend only cares for the values it receives – kero Jun 27 '16 at 09:18
  • Oh, I see. any demo code for javascript? thanks! – Kai Huang Jun 27 '16 at 09:31
  • You could do it [like so](https://jsfiddle.net/339rfesw/), or if you want to listen to all changes (and see the email input live while typing), read [this answer](http://stackoverflow.com/questions/1948332/detect-all-changes-to-a-input-type-text-immediately-using-jquery) – kero Jun 27 '16 at 10:12
  • hi kero thank you so much!! works perfectly! – Kai Huang Jun 27 '16 at 10:30

0 Answers0