Which method doesn't let you pass attributes?

-------------------------------------
Francois<[email protected]> wrote:

Le 26/01/2010 18:25, David Pollak a écrit :
>
> It's not possible today.  Do you have an idea of what the API should
> look like?

I believe that a simple select with a Seq[(String, Seq[(T,String)])] 
could be sufficient.

On the other hand, there is already a lot of selectbox related methods 
in SHtml, and I think that they miss some possibilities (for example, 
adding attributes, especially class, to option).

So, I was thinking to something more general, like what is at the 
bottom, with a "full feature" option model, group model, and "select 
options".

Or perhaps it would be even nicer to have less select methods, with some 
implicits for common use case ( Seq[String,String)] as option, in 
particular)


Thanks for you time,

(the formating in the mail is bad, so I also join the source in a file)

8<------------ Code proposition for select model ------------------
/**
  * A full featured option tag
  */
case class OptionModel[T](value:T, label:String, disabled:Boolean, 
attrs:(String,String)*)

/**
  * Option Group
  */
case class OptionGroupModel[T](label:String, 
options:Seq[OptionModel[T]], disabled:Boolean, attrs:(String,String)*) {
   def values = options map( _.value )
}

/**
  *  Options : list of ungrouped options
  *  OptionGroups : the list of groups of options.
  */
case class 
SelectOptions[T](options:Seq[OptionModel[T]],groups:Seq[OptionGroupModel[T]]) 
{
   def values = (options map( _.value)) ++ (groups map( _.values))
}



object SHtml {

   // ....
   private def selected(in: Boolean) = if (in) new 
UnprefixedAttribute("selected", "selected", Null) else Null
   // ....

   private def disabled(in: Boolean) = if (in) new 
UnprefixedAttribute("disabled", "true", Null) else Null

   def select_*(opts: SelectOptions[String], deflt: Box[String], func: 
AFuncHolder, attrs: (String, String)*): Elem = {
     //build an <option> from an option model
     def buildOption(option:OptionModel[String]) = {
       option.attrs.foldLeft(
         <option value={option.value}>{option.label}</option> % 
disabled(option.disabled) % selected(deflt.exists(_ == option.value))
       )(_ % _)
     }

     val testFunc = LFuncHolder(in => in.filter(v => 
opts.values.contains(v)) match {case Nil => false case xs => func(xs)}, 
func.owner)

     attrs.foldLeft(fmapFunc(testFunc)(fn => <select name={fn}>{
       //start with groups
       opts.groups.flatMap { group =>
         group.attrs.foldLeft(<optgroup label={group.label}>{
           //each option in a groups, with its attributes
           group.options.flatMap { buildOption(_) }
         }</optgroup> % disabled(group.disabled) )(_ % _)
       } ++
       //now, option that are not in a group
       opts.options.flatMap { buildOption(_) }
     }</select>))(_ % _)
   }

}
8<--------- end code proposition for select model -----------------

-- 
Francois ARMAND
http://fanf42.blogspot.com

-- 
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.

-- 
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.

Reply via email to