I have a view called contact.html.twig. It has a form with some textfields. I want to use javascript to validate that none of the fields are empty, as well as some other rules. But I do not know where to put the .js with the definitions. I do not know either how to call the .js script using the Twig notation.
Tell me more
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
This is a generic answer for how to handle javascript... not specifically the validation part. The approach I use is to store individual functionality in separate JS files as plugins in the bundles
I then include these files in my base template using assetic:
In my base template I have a block at the end of
Then in my page that has the "user admin" functionality I can call the userAdmin function like so:
|
|||
|
Isn't basic HTML5 functionality enough for your client side validation? It is provided by the Form component. You could also check: |
||||
|