Modify Checkbox HTML code generated by MappedBoolean

58 views
Skip to first unread message

Sam

unread,
Apr 24, 2012, 11:46:43 AM4/24/12
to lif...@googlegroups.com
I define a MappedBoolean field on CRUDify:

object status extends MappedBoolean(this) {

    override def displayName = "Status"

    override def toString =  if(this) "Enable" else "Disable"

    override def defaultValue = true

}

And it generates the following HTML code:

<tr>
          <td>
            Status
          </td>
          <td>            <input value="true" type="checkbox" name="F280400493864BO3SHX" checked="checked"><input value="false" type="hidden" name="F280400493864BO3SHX">
          </td>
</tr>


I wanna there has a text label "Active" behind the checkbox to generate the HTML code like this:

            <input value="true" type="checkbox" name="F280400493864BO3SHX" checked="checked">Active</input>

I've tried to override formElemAttrs, but not work. 

Are there other ways?

Thanks!

Sam


Robert Marcano

unread,
Apr 25, 2012, 7:30:24 PM4/25/12
to lif...@googlegroups.com
On Tue, Apr 24, 2012 at 11:16 AM, Sam <s...@samuel.pro> wrote:
I wanna there has a text label "Active" behind the checkbox to generate the HTML code like this:

            <input value="true" type="checkbox" name="F280400493864BO3SHX" checked="checked">Active</input>

I've tried to override formElemAttrs, but not work. 

Are there other ways?


Override toForm

override def toForm = super.toForm match {
  case Full(n) => Full(<label>{ n } Active</label>)
  case x => x
}

Note: input element has no content modes (must not have child nodes), use label

--
Robert Marcano

Robert Marcano

unread,
Apr 25, 2012, 7:35:14 PM4/25/12
to lif...@googlegroups.com
forgot to add:

Or use Box.map()

override def toForm = super.toForm.map(ns => <label>{ ns } Active</label>)

Sam

unread,
May 4, 2012, 11:25:38 AM5/4/12
to lif...@googlegroups.com
Dear Robert,

Thank you very much for your help.

It's works now.

Sam
Reply all
Reply to author
Forward
0 new messages