Search code examples
perlmojolicious

define textarea as required with mojolicious tag helper


How do i define an textarea as required with mojolicious tag helper?

I need to generate a textarea like this

<textarea name="comment" required></textarea>

When trying to do the same with tag helper

%= text_area 'comment', 'required'

I get

<textarea name="comment">required</textarea>

Solution

  • Mojo tag helpers will simply pass extra attributes through (see sub _tag in the source).

    In HTML5, an empty attribute can be declared as attr="" (docs here).

    So, based on the Mojo text_area docs, the syntax would be:

    %= text_area 'comment', required => ''