0

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>
David Michael Gang
  • 7,107
  • 8
  • 53
  • 98

2 Answers2

3

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 => ''
codnodder
  • 1,674
  • 9
  • 10
  • but this produces . This is not the same as – David Michael Gang Dec 25 '13 at 14:22
  • 1
    According to the HTML5 spec they are the same. I am not aware of any way to create empty attributes in mojo. Best. – codnodder Dec 25 '13 at 18:47
  • You are right www.w3.org/TR/html5/infrastructure.html#boolean-attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace – David Michael Gang Dec 26 '13 at 07:25
1
%= text_area 'comment', required => '1'

here

devrow
  • 86
  • 5
  • 3
    Please turn this into an answer. Make yourself comfortable with the editing tools, give it some love. – hakre Dec 25 '13 at 13:59
  • I looked in the hrml5 spec and it does not look like a valid option www.w3.org/TR/html5/infrastructure.html#boolean-attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace, so 1 is not valid but required => 'required' is one – David Michael Gang Dec 26 '13 at 07:27