recursive_acronym
recursive_acronym

Reputation: 3031

html - form table - invalid markup

I understand it is incorrect to have a form inside a table row. There does seem to be a practical reason for doing this though.

I would like to be able to edit each row individually (ajax and such), so it makes sense that each for is its own form.

Below is functionally how I need the table and form to be laid out, but the markup isn't valid. And furthermore, haml/erb actually won't process the markup like this (the form is opened and closed within the first cell).

I could use display: table-cell and such, but I think the data I'm displaying does belong in a table, semantically.

How can I accomplish the same function with proper markup?

<table>
<thead>
  <tr>
    <th>id</th>
    <th>name</th> 
    <th>email</th>
    <th>phone</th>
    <th>address</th> 
  </tr>
</thead>
<tbody>
  <tr>
    <%= form_for person do |f| %>
      <td><%= id %></td>
      <td><%= f.text_field :name%></td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    <% end %>
  </tr>
</tbody>
</table>

Upvotes: 1

Views: 2992

Answers (1)

weexpectedTHIS
weexpectedTHIS

Reputation: 3376

<table>
<thead>
  <tr>
    <th>id</th>
    <th>name</th> 
    <th>email</th>
    <th>phone</th>
    <th>address</th> 
  </tr>
</thead>
<tbody>
  <tr>
    <td>
      <%= form_for person do |f| %>
        <table>
          <tr>
            <td><%= id %></td>
            <td><%= f.text_field :name%></td>
            <td>...</td>
            <td>...</td>
            <td>...</td>
          </tr>
        </table>
      <% end %>
    </td>
  </tr>
</tbody>
</table>

Upvotes: 2

Related Questions