Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play2 form attributes with - in them "value - is not a member of Symbol"

I've just got started with Play2 and I'm struggling with scala.

In a view I've got this simple form helper to create a news item.

@textarea(
  newsItemForm("content"),
  '_label -> "Content",
  'rows -> 3,
  'cols -> 50,
)

Now I'd like to add a data-wysiwyg to the attributes, but since it contains a - scala complains about - not being a member of Symbol.

since ' is just a nice way of writing Symbol("data-wysiwyg") I can get it working, but then my views will look ugly with some attributes beeing specified with Symbol and others with '

My question is: is there a way to use the scala ' notation for html5 data- attributes?

like image 875
Leon Radley Avatar asked Apr 12 '12 14:04

Leon Radley


2 Answers

You can also use the apply method of the Symbol companion object. I think this is more readable, as it makes it very obvious that you're creating a symbol:

scala> Symbol("data-wysiwyg");
res0: Symbol = 'data-wysiwyg
like image 102
Mike Avatar answered Sep 22 '22 14:09

Mike


I don't think it's possible because the dash will be interpreted as a minus sign. If the matter is to shorten the declaration, why not add a method s to strings to produce the corresponding symbol (akin to the r method for producing regexp) ?

class SymbolString( str: String ) {
  def s = Symbol(str)
}

implicit def str2symstr( str: String ) = new SymbolString(str)

scala> "hello".s
res20: Symbol = 'hello

scala> "data-wysiwyg".s
res21: Symbol = 'data-wysiwyg
like image 44
paradigmatic Avatar answered Sep 22 '22 14:09

paradigmatic