Search code examples
lift

SHtml.textarea as a CssSel


Is there any way to create a CssSel that has a SHtml.textarea/SHtml.text/SHtml.input/SHtml.button logic?

What I want is, having a NodeSeq

<textarea class="dontDeletePlease"></textarea>

and a CssSel like

"*" #> SHtml.textarea(...)

have a result

<textarea class="dontDeletePlease" onsubmit="..." name="..."></textarea>

But, instead, I'll get the class "dontDeletePlease" erased. And all other attributes too.

Is there any way to create a CssSel that would apply it's logic keeping the html attributes?


Solution

  • I think you have two options. You can use Lift's funcMap to add the function directly to your existing textarea. This will not modify anything except to add a name attribute directly to your tag. This is similar to what Lift does internally with SHtml.textarea.

    "*" #> {
      fmapFunc(SFuncHolder((t) => //do something))(funcName =>
        "* [name]" #> funcName
      )
    }
    

    The other is to grab the attributes from within the CSS Selector and pass them to your transformation, like this:

    "*" #> { ns:NodeSeq =>
      ns.map{ n =>
        val ta = SHtml.textarea("", (t) => //do something)
        ta % n.attributes
      }
    }
    

    That will use SHtml.textarea to create an input, and then add all of the attributes from the existing element to the new one.