Home > Back-end >  How to add a name attribute to a textarea?
How to add a name attribute to a textarea?

Time:11-02

I am currently struggling to add a name attribute to a textarea.

It's supposed to look like this in HTML:

<textarea name="comment">Enter text here...</textarea>.

For example in Ktor HTML DSL I can do this with an input field:

textInput(name = "username"), but it doesn't work for a textarea.

Is there a way to add a name property?

Maybe someone has some experience with Kotlin Ktor and HTML DSL.

Thank you.

CodePudding user response:

To add any attributes to a textarea create an instance of the TEXTAREA class:

get("/") {
    call.respondHtml(HttpStatusCode.OK) {
        body {
            TEXTAREA(mapOf("name" to "some-name"), consumer).visit {
                // Add child nodes here
            }
        }
    }
}
  • Related