dev.pus
dev.pus

Reputation: 8139

Backbone: Forms without form tag valid?

I want to ask if it is legitim to do:

<textarea name="message"></textarea>

instead of;

<form><textarea name="message"></textarea></form>

In both cases Backbone will handle the form content the benefit would just be that I don't have to prevent the default behaviour of the form submittion. I am just unsure if this is a "good" practise.

Upvotes: 0

Views: 408

Answers (2)

mu is too short
mu is too short

Reputation: 434765

From the HTML5 spec for <textarea>:

Permitted parent elements

Any element that can contain phrasing elements.

So yes, you can put a <textarea> outside a <form>, no worries.

Upvotes: 1

Brian Nickel
Brian Nickel

Reputation: 27560

There's nothing wrong with it. The HTML spec doesn't mandate that a textarea be placed in a form, nor does it describe a default action to take if it isn't. Placing the item in a form would only make sense if you were using the default form action.

There are two potential issues. The first would be in the non-semantic case where you have a textarea statically inside the page with no non-scripted action. That is, if a user saw your page with JavaScript turned off, they'd see a useless textarea. I assume from the use of Backbone that you are generating the textarea and this is not an issue.

The second is that you are using the name attribute. This attribute has special meaning for forms and is less powerful outside of forms than ID. You could run into the terrible case where your component is placed in a form by another developer and the value gets passed to the server by mistake. This kind of thing does happen.

Upvotes: 2

Related Questions