html5 multiple submits in play framework

I need to do something like this with the play framework 2.1:

@form(routes.PedidoCtrl.carregaTabela){
   //...
   <input type="submit" value="Page 1">
   <input type="submit" formaction="????" value="Page 2">
   <input type="submit" formaction="????" formmethod="post" value="Page 3">
}

But what should i put in the "formaction" field? I've never used the "formaction" attribute, but i saw thar is what i want to do in this page: http://cbsa.com.br/post/formulario-com-multiplos-submit-e-method-em-html5.aspx (portuguese)

Thanks for the attention.

Upvotes: 0

Views: 182

Answers (1)

estmatic
estmatic

Reputation: 3449

I had never seen that either but it seems extremely useful.

You would use the same reverse routing that you're already using on the @form helper. I modified your sample code. Obviously just replace "action2" and "action3" with whatever your other action methods are.

@form(routes.PedidoCtrl.carregaTabela){
  //...
  <input type="submit" value="Page 1">
  <input type="submit" formaction="@routes.PedidoCtrl.action2" value="Page 2">
  <input type="submit" formaction="@routes.PedidoCtrl.action3" formmethod="@routes.PedidoCtrl.action3.method" value="Page 3">
}

Note the @ escape character in front of "routes.PedidoCtrl..."

The reverse routing returns a play.api.mvc.Call instance. That class has an url() method which is what is getting output for your formaction attribute (it's calling toString which in turn calls url). There's also the method() method which you can use for the formmethod attribute.

Upvotes: 1

Related Questions