Hi! I’d like to get some feedback on how I should build a component for my table row.
I’d like the row to be plain text, and then when the user clicks the edit button, it turns the columns into input fields.
I have two questions:
- When I call the component and pass in the appropriate variables, I’m getting an error: Uncaught TypeError: Cannot read property ‘firstChild’ of null
- How do I tell a specific row that I’d like it to switch to the editing view?
Here’s my Template:
<table class="services table">
<thead>
<tr>
<td>date</td>
<td>type</td>
<td>description</td>
<td>price/per</td>
<td>quantity</td>
<td>total</td>
<td>actions</td>
</tr>
</thead>
<tbody class="table-striped">
{{#each services}}
{{service-table-row service=newService servicePer=servicePer serviceTypes=serviceTypes}}
{{/each}}
<tr>
<td colspan="5" class="total-title">Total:</td>
<td colspan="2" class="total-amount">${{controllers.project.total}}</td>
</tr>
</tbody>
<tfoot class="add-service form-inline" role="form">
{{service-table-row service=newService servicePer=servicePer serviceTypes=serviceTypes isEditing=true}}
</tfoot>
</table>
My component template:
<tr>
<td>
{{#if isEditing}}
<label for="date" class="sr-only">Date:</label>
{{input type="date" value=date class="form-control input-sm"}}
{{else}}
{{date}}
{{/if}}
</td>
<td>
{{#if isEditing}}
<label for="type" class="sr-only">Type:</label>
{{view Ember.Select content=serviceTypes value=type class="form-control input-sm"}}
{{else}}
{{type}}
{{/if}}
</td>
<td>
{{#if isEditing}}
<label for="description" class="sr-only">Description:</label>
{{input type="text" value=description class="form-control input-sm input-description"}}
{{else}}
{{description}}
{{/if}}
</td>
<td>
{{#if isEditing}}
<label for="price" class="sr-only">Price:</label>
{{input type="number" value=price class="form-control input-sm"}}/
{{view Ember.Select content=servicePer value=per class="form-control input-sm"}}
{{else}}
${{price}}/{{per}}
{{/if}}
</td>
<td>
{{#if isEditing}}
<label for="quantity" class="sr-only">Quantity:</label>
{{input type="number" value=quantity class="form-control input-sm"}}
{{else}}
{{quantity}}
{{/if}}
</td>
<td>
${{total}}
</td>
<td>
{{#if isEditing}}
<button {{action 'addService'}} class="btn btn-primary btn-xs">Add</button>
{{else}}
<a {{action 'editService' this}} class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span> Edit</a> <a {{action 'removeService' this}} class="btn btn-warning btn-xs"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
{{/if}}
</td>
</tr>
This is my first post, so if I’m missing something, just let me know.
Thanks!