Re: [play-framework] Set checkbox default value to true

1,768 views
Skip to first unread message

C. Mundi

unread,
Jul 12, 2012, 1:18:18 AM7/12/12
to play-fr...@googlegroups.com


On Wed, Jul 11, 2012 at 11:54 AM, Xiang Zhang <stanleyz...@gmail.com> wrote:
Hi I'm new to Playframework. I got a very simply question: how do I set the checkbox default value to true? The following is the code piece in the view:
                <fieldset>
@for(name <- list) {
@checkbox(
                searchForm(name), 
                '_label -> None, '_text -> name,
                '_showConstraints -> false,
            )
}
</fieldset>
I basically want all fields to be pre-selected and passed to another controller as a GET request.

Thanks!

I am learning Play! and would also like to know the answer to the OP's question.  Every web framework has its own pattern for marking up HTML tag entities, and this is as good an example as any for me!

zievereir

unread,
Aug 15, 2012, 5:23:04 PM8/15/12
to play-fr...@googlegroups.com
Stumbled on this post while looking for an answer for this myself, so might as well answer it. The checkbox-helper allows you to add extra htmlarguments at the end, you can use that to set the checkbox checked by default. See following example:

@checkbox(myForm("checkMe"), '_label -> Messages("check_me.text"), 'checked -> "checked")

Do check the checkbox.scala.html file in your Play sourcecode, cause there was a little bug that prevented specified htmlargs from being added to the checkbox:

@toHtmlArgs(htmlArgs.filterKeys(_ == 'value))>

Needs to be:

@toHtmlArgs(htmlArgs.filterKeys(_ != 'value))>
Reply all
Reply to author
Forward
0 new messages