CSS Selectors: Multiple classes on an element

253 views
Skip to first unread message

Bufferine

unread,
Nov 24, 2010, 12:50:59 AM11/24/10
to Lift
Only the first declared class is picked up.

val xml = <a class="link field" href="#">link text</a>
val func =
".field [id]" #> "fieldId" &
".link [href]" #> "http://example.org"


println(func.apply(xml)) ml))

results in

<a href="http://example.org" class="link field">link text</a>

reverse the class declarations and you get

<a id="fieldId" href="#" class="field link">link text</a>

I had a look through the code around the fix dpp did for the multiple
ids in css selector (http://groups.google.com/group/liftweb/
browse_thread/thread/c50d6ee416f77692/0f2b532956a592a8?lnk=gst&q=css
+selector+class#0f2b532956a592a8)

and the problem I think is with

def findClass(clz: List[String]): Box[List[CssBind]] = clz match {
case Nil => Empty
case x :: xs =>
clzMap.get(x) match {
case Some(cb) => Full(cb)
case _ => findClass(xs)
}
}

line 1782 in framework/lift-base/lift-util/src/main/scala/net/liftweb/
util/BindHelpers.scala

If I'm reading this right, it'll only find the first match.

My use case is that I have a table full of events, which can be
suspended (so would be greyed out to customers) or unpublished (so
would be hidden from customers). Someone in an admin interface could
change these statuses and the front end automatically hides/greys out
the corresponding rows. The designer would flag the elements that he
wanted to change on these actions with the suspendable or publishable
class (perhaps he wants the whole row to grey out, perhaps just the
description for example), and in the back end I would use that info in
my bindings to attach element ids/classes for the suspended/
unpublished opps. As an admin changed the status, my Comet Actor sends
out further javascript to hide/change the classes on the opps.

Hmm - verbal may not be clear:

HTML:

<div class="event"> <tr class="suspendable publishable" >
<td > <span class="event_desc_w">Default event
description </span> </td>
</tr></div>

should become

<div class="event"> <tr class="suspendable publishable
suspended" id="event_1" style="display: none;">
<td > <span class="event_desc_w"
id="event_desc_1">unpublished, suspended event </span> </td>
</tr></div>

using selectors:

& ".unpublishable [id]" #> ("event_id_" +
event.id.is.toString)
& ".unpublishable [style]" #> {
if (event.published.is == false) {
"display: none;"
} else {
"display: block"
}
}
& ".suspendable [id]" #> ("event_id_" +
event.id.is.toString) // id needs to be set - may not be both
publishable and suspendable
& ".suspendable [suspended]" #> {if (event.suspended.is ==
false) {"suspended"} else {"unsuspended"}}


<js update code upon message omitted>


Each class works individually, but obviously doesn't work if I put
them both in.

I think this is probably a bug, as multiple classes is a pretty common
thing, and there are classes to support adding multiple classes in
lift.

I can file the bug, and write the test, and have a think about how
this could be fixed - but my scala fu is still pretty weak.

Catherine

Bufferine

unread,
Nov 24, 2010, 12:53:34 AM11/24/10
to Lift
No, my proposed bug location isn't it - I'll keep looking.

David Pollak

unread,
Nov 24, 2010, 7:16:59 PM11/24/10
to lif...@googlegroups.com
2.2-SNAPSHOT contains the ability to have multiple rules apply to the same node:

Are you suggesting that if multiple rules match, all the rules should be applied?


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Catherine Jung

unread,
Nov 24, 2010, 8:19:49 PM11/24/10
to lif...@googlegroups.com
I think that it's unexpected behaviour that if you put more than one
class on an element, that only rules matching the first one will be
applied. Especially since if you only have one rule, it'll apply to a
class element in any position of the list.

Catherine

David Pollak

unread,
Nov 24, 2010, 8:23:12 PM11/24/10
to lif...@googlegroups.com
On Wed, Nov 24, 2010 at 5:19 PM, Catherine Jung <catheri...@gmail.com> wrote:
I think that it's unexpected behaviour that if you put more than one
class on an element, that only rules matching the first one will be
applied. Especially since if you only have one rule, it'll apply to a
class element in any position of the list.

Okay... open a ticket at http://tickets.liftweb.net (you have to be a watcher of the assembla space)
 

Catherine Jung

unread,
Nov 24, 2010, 9:48:22 PM11/24/10
to lif...@googlegroups.com

David Pollak

unread,
Nov 24, 2010, 11:39:57 PM11/24/10
to lif...@googlegroups.com

Catherine Jung

unread,
Nov 25, 2010, 12:05:50 AM11/25/10
to lif...@googlegroups.com
Thanks very. very much - I'll grab/build the latest and greatest.

Reading what you did to make the change is helpful too.

Catherine

On Wed, Nov 24, 2010 at 8:39 PM, David Pollak

Reply all
Reply to author
Forward
0 new messages