how to conditionally mark a SHtml.checkbox as disabled

Showing 1-3 of 3 messages
how to conditionally mark a SHtml.checkbox as disabled Damian Helme 8/3/12 1:59 PM
I want to add the 'disabled' attribute to a SHtml.checkbox based on a conditional check. 

The only way I've found so far is:

   "#isShared" #> SHtml.checkbox(isSharedRV.is, processIsShared(_))
                                      .map(x => x.asInstanceOf[scala.xml.Elem] % ("disabled" -> (if (!isOwner) "disabled" else Empty)))

The trick that's being used here is that if you call '% ("disabled -> Empty)' on an Elem then the 'disabled' attribute gets ignore altogether. 

However, the complicating factor is that SHtml.checkbox returns a NodeSeq rather than an Elem, so you can't apply the % operator directly as you could with, say, SHtml.text.

It feels a bit too clunky. Is there a better / easier way that I've missed?

Thanks

Damian

Re: [Lift] how to conditionally mark a SHtml.checkbox as disabled David Pollak 8/3/12 2:28 PM


On Fri, Aug 3, 2012 at 1:59 PM, Damian Helme <damia...@gmail.com> wrote:
I want to add the 'disabled' attribute to a SHtml.checkbox based on a conditional check. 

The only way I've found so far is:


"#isShared" #> (if (!isOwner) "* [disabled]" #> "disabled" else PassThru ).apply(SHtml.checkbox(isSharedRV.is, processIsShared(_)))
 

   "#isShared" #> SHtml.checkbox(isSharedRV.is, processIsShared(_))
                                      .map(x => x.asInstanceOf[scala.xml.Elem] % ("disabled" -> (if (!isOwner) "disabled" else Empty)))

The trick that's being used here is that if you call '% ("disabled -> Empty)' on an Elem then the 'disabled' attribute gets ignore altogether. 

However, the complicating factor is that SHtml.checkbox returns a NodeSeq rather than an Elem, so you can't apply the % operator directly as you could with, say, SHtml.text.

It feels a bit too clunky. Is there a better / easier way that I've missed?

Thanks

Damian

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
 
 



--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Re: [Lift] how to conditionally mark a SHtml.checkbox as disabled Damian Helme 8/5/12 2:38 AM
neat - thanks!