The World’s Largest Online Community for Developers

'; how to add onsubmit in scala form tag - LavOzs.Com

I am new to scala and need to make a small change in the form tag. Currently the form tag in my html page is written like

@form(routes.LoginController.loginAuthenticate) {

I need to add onsubmit property in this form tag. I tried like

@form(routes.LoginController.loginAuthenticate, 'onSubmit' => 'validate()') {

but it is giving error.

Please suggest how can i add it.

A Play Twirl templates expects after an @ Scala code, not Javascript.

So 'onSubmit' => 'validate()' is not valid.

It must be 'onSubmit -> "validate()"

Be aware with Scala 2.13 'onSubmit is deprecated.

You should look at the method definition. apply method takes action: Call and args: (Symbol, String)*.

def apply(action: Call, args: (Symbol, String)*)(body: ⇒ Html): Appendable

Your code should be like this

@form(routes.LoginController.loginAuthenticate, 'onSubmit -> "validate()") {
  • Tuple A -> B == (A, B)
  • Symbol 's == Symbol("s")
  • String "string"
  • Character 'c'
  • => is for function
JavaScript post request like a form submit
How to align checkboxes and their labels consistently cross-browsers
In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
How to prevent buttons from submitting forms
Is it a good practice to use an empty URL for a HTML form's action attribute? (action=“”)
How to add ID property to Html.BeginForm() in mvc?
HTML5 form required attribute. Set custom validation message?
Submitting a form with onclick and onsubmit
javascript change form onsubmit dynamically
Form onsubmit issues?