Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<input> cannot appear as a child of <tr>

Tags:

html

reactjs

I want to add a <input> element, more specifically a checkbox, in my table. The following works:

<tbody key={rule._id}>
  <tr>
    <td>{rule.deviceId}</td>
    {
      <input
        name="isEnabled"
        type="checkbox"
        checked={rule.enabled}
      />
    }
    <td>{rule.name}</td>
  </tr>
</tbody>

but it produces an error in the console: <input> cannot appear as a child of <tr>

Is there a 'proper' way to do this?

like image 583
grpcMe Avatar asked Aug 22 '17 10:08

grpcMe


3 Answers

Put the <input> inside a <td>.

like image 193
Quentin Avatar answered Nov 07 '22 04:11

Quentin


You missed one <td> pair. Also the { and } are not required. Should be like that

<tbody key={rule._id}>
  <tr>
    <td>{rule.deviceId}</td>
    <td>
      <input
        name="isEnabled"
        type="checkbox"
        checked={rule.enabled} />
    </td>
    <td>{rule.name}</td>
  </tr>
</tbody>
like image 35
Fotis Avatar answered Nov 07 '22 04:11

Fotis


tr can only contain td. You should wrap your input with a td.

<tbody key={rule._id}>
  <tr>
    <td>{rule.deviceId}</td>
    <td> 
      <input
        name="isEnabled"
        type="checkbox"
        checked={rule.enabled}
      />
    </td>
    <td>{rule.name}</td>
  </tr>
</tbody>
like image 1
An Nguyen Avatar answered Nov 07 '22 06:11

An Nguyen