html - How to apply an `onclick` event to multiple radio button options in Scala Play? -


i'm using play framework in scala.
have radio button lets choose between 2 options form:

@helpers.inputradiogroup(searchform("options"), seq("option1" -> "option 1", "option2" -> "option 2")) 

i have form doesn't use helpers , has onclick events send data google analytics depending on option choose:

<form>     <input type="radio" name="option1" onclick="ga('send', 'event', { eventcategory: 'searchform', eventaction: 'options', eventlabel: 'option1'})" value="@searchform("options")">option 1<br>     <input type="radio" name="option2" onclick="ga('send', 'event', { eventcategory: 'searchform', eventaction: 'options', eventlabel: 'option2'})" value="@searchform("options")">option 2<br> </form> 

my question how apply second form's onclick events first example?

each of helper objects inputradiogroup has apply method documented here, example (for play 2.3): https://www.playframework.com/documentation/2.3.x/api/scala/index.html#views.html.helper.inputradiogroup$

here's definition of apply:

def apply(   field: field,   options: seq[(string, string)],   args: (symbol, any)*)(   implicit handler: fieldconstructor, lang: lang):    play.twirl.api.htmlformat.appendable 

and example documentation

@inputradiogroup(   contactform("gender"),   options = seq("m"->"male","f"->"female"),   '_label -> "gender",   '_error -> contactform("gender").error.map(_.withmessage("select gender"))) 

we see tag attributes provided varargs in form of pair of symbol , any. so, can rewrite tag follows:

@helpers.inputradiogroup(   searchform("options"),   seq("option1" -> "option 1", "option2" -> "option 2"),   'onclick -> "ga('send', 'event', { eventcategory: 'searchform', eventaction: 'options', eventlabel: 'option1'})" ) 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -