Any easy way of modifying existing attr of a tag

60 views
Skip to first unread message

Chung Onn Cheong

unread,
Jul 7, 2015, 9:22:53 PM7/7/15
to scal...@googlegroups.com
Hi,

I have a tag input(cls:="btn") and I would like to append or replace the value of an existing attr like cls:="btn-primary". I found that only new attrs are added but existing attr is not modified. Is there a way to modify existing attr of a tag?

scala> import scalatags.Text.all._
import scalatags.Text.all._

scala> input(cls:="btn", tpe:="submit")(cls:="btn-primary", "new".attr:="new")
res0: scalatags.Text.TypedTag[String] = <input class="btn" type="submit" new="new" />


chungonn

Haoyi Li

unread,
Jul 26, 2015, 1:14:23 AM7/26/15
to Scalatags, chun...@gmail.com, chun...@gmail.com
There currently isn't one; generally tags are best thought of as write-only. If you want to pass in more classes into your input, just thread the extra classes down the callstack to the point where they would be used.

Chung Onn Cheong

unread,
Aug 2, 2015, 1:17:07 AM8/2/15
to Scalatags, chun...@gmail.com
My preference is to use scalatags as much as possible without building things around it. Btw, I am using scalatags as a replacement for twirl in Play 2. Thanks for sharing this really nice library. When I have more time I would be keen to explore the DOM library.

Haoyi Li

unread,
Aug 3, 2015, 12:33:55 AM8/3/15
to Chung Onn Cheong, Scalatags
My preference is to use scalatags as much as possible without building things around it

Well you're in the wrong place then. The whole point of Scalatags is to let you build your own things around it to make your life better =D

To the point of class appending, there's been discussion on the gitter channel, and it's <5 lines of code to implement it yourself, so you should come hang out and check it out =P

--
You received this message because you are subscribed to the Google Groups "Scalatags" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatags+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chung Onn Cheong

unread,
Aug 3, 2015, 1:55:50 AM8/3/15
to Haoyi Li, Scalatags
Well you're in the wrong place then. The whole point of Scalatags is to let you build your own things around it to make your life better =D
 Your work has made my life a lot better actually. Btw, I did some minor extensions like retrieving attrs from the tag directly. However I thought a better thing to do is to check with the folks here if they have a solution to the same problem.


To the point of class appending, there's been discussion on the gitter channel, and it's <5 lines of code to implement it yourself, so you should come hang out and check it out =P
I did shallow dive into the source and been to the gitter. I guess I must have missed the part the part about class appending. Yes, I will hang out more at the gitter channel.

Thanks once again.

Haoyi Li

unread,
Aug 3, 2015, 2:00:15 AM8/3/15
to Chung Onn Cheong, Scalatags
Here was the bit of code I linked in gitter:


It's used in Scalatag's inbuilt stylesheet support, and can trivially repurposed for your own appending-classes-together =)

Chung Onn Cheong

unread,
Aug 3, 2015, 2:04:13 AM8/3/15
to Haoyi Li, Scalatags
Awesome! 

Thanks a million, Haoyi!
Reply all
Reply to author
Forward
0 new messages