Jonathan, Please see my patch at http://github.com/dpp/liftweb/commit/d79513340a0701f391f0ad474298f2c5bd7dd2fa
Thanks for the suggestion and welcome to the Lift community. David On Wed, Jun 10, 2009 at 9:19 PM, Jonathan Meeks <[email protected]>wrote: > > Here's what I came up with. It seems to work. > > I don't know how well it will appear inlined in a posting. Let if you > want it delivered in another fashion. > > diff --git a/lift/src/main/scala/net/liftweb/http/SHtml.scala b/lift/ > src/main/scala/net/liftweb/http/SHtml.scala > index 22c4832..58e6069 100644 > --- a/lift/src/main/scala/net/liftweb/http/SHtml.scala > +++ b/lift/src/main/scala/net/liftweb/http/SHtml.scala > @@ -430,13 +430,28 @@ object SHtml { > private[http] def secureOptions[T](options: Seq[(T, String)], > default: Box[T], > onSubmit: T => Unit): (Seq > [(String, String)], Box[String], AFuncHolder) = { > val secure = options.map{case (obj, txt) => (obj, randomString > (20), txt)} > - val defaultNonce = default.flatMap(d => secure.find(_._1 == d).map > (_._2)) > + val defaultNonce = default.map(secureDefaultNonce(secure, _)) > val nonces = secure.map{case (obj, nonce, txt) => (nonce, txt)} > def process(nonce: String): Unit = > secure.find(_._2 == nonce).map(x => onSubmit(x._1)) > (nonces, defaultNonce, SFuncHolder(process)) > } > > + private[http] def secureOptions[T](options: Seq[(T, String)], > default: Seq[T], > + onSubmit: T => Any): (Seq > [(String, String)], Seq[String], LFuncHolder) = { > + val secure = options.map{case (obj, txt) => (obj, randomString > (20), txt)} > + val defaultNonce = default.map(secureDefaultNonce(secure, _)) > + val nonces = secure.map{case (obj, nonce, txt) => (nonce, txt)} > + def process(nonces: List[String]): Any = > + nonces.map(nonce => secure.find(_._2 == nonce).map(x => onSubmit > (x._1))) > + (nonces, defaultNonce, LFuncHolder(process)) > + } > + > + private def secureDefaultNonce[T](secureOptions: Seq[(T, String, > String)], default: T): String = { > + secureOptions.find(_._1 == default).get._2 > + } > + > + > /** > * Create a select box based on the list with a default value and > the function to be executed on > * form submission > @@ -518,6 +533,22 @@ object SHtml { > func: List[String] => Any, attrs: (String, String) > *): Elem = > multiSelect_*(opts, deflt, LFuncHolder(func), attrs :_*) > > + /** > + * Create a select box based on the list with a default value and > the function > + * to be executed on form submission > + * > + * @param options -- a list of value and text pairs (value, text > to display) > + * @param default -- the default value (or Empty if no default > value) > + * @param onSubmit -- the function to execute on form submission > + */ > + def multiSelectObj[T](options: Seq[(T, String)], default: Seq[T], > + onSubmit: T => Unit, attrs: (String, String)*): > Elem = { > + val (nonces, defaultNonce, secureOnSubmit) = > + secureOptions(options, default, onSubmit) > + > + multiSelect_*(nonces, defaultNonce, secureOnSubmit, attrs:_*) > + } > + > def multiSelect_*(opts: Seq[(String, String)], > deflt: Seq[String], > func: AFuncHolder, attrs: (String, String)*): > Elem = > > > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
