user1834464
user1834464

Reputation:

Single page applications and <form> elements

Are there still any benefits of using a <form> element instead of let's say a <div> element in the context of a single page application? The purpose of the <form> element makes sense to me if the "form" submission isn't made with an ajax call (I'm talking about the more traditional way of submitting a form, with a input/button of type "submit" and the action attribute of the form element that describes the url to call), but otherwise I do not see it's utility (maybe for search engines?).

Upvotes: 16

Views: 5510

Answers (3)

Display name
Display name

Reputation: 1542

No, you don't. The form tag, in terms of SPAs is largely archaic. However, it can be beneficial for accessibility issues.

As an alternative, you can specify roll="form".

<div role="form" 

In general, there's no down side to use form. And, there are several good reasons to use the form tag, and only very few against. Treat it like a wrapping div tag around your input elements: also, you don't have to use the submit action.

Upvotes: 0

OsamaBinLogin
OsamaBinLogin

Reputation: 647

I think the answer is, no, if you're not going to "submit" a form, there's no need for the <form tag. Very often, our interactive controls are in places that would not be considered a "form" - checkboxes here, select menus there. I think most of them work just fine without a

Accessibility, I don't know anything about.

Upvotes: -1

Leo
Leo

Reputation: 13838

  1. Semantically, using <form> is clearer than <div>.
  2. If you still want your form to work without JavaScript, you'd better choose <form> (since you used the word application, this may not be considered though).
  3. More importantly, it'll be really painful of using <div> if you do care about accessibility.

Upvotes: 8

Related Questions