I have an HTML table as below:
<table class="table table-bordered">
<tr>
<th>User Id</th>
<th>Name</th>
<th>Address</th>
<tr>
<tr ng-repeat="item in respose">
<td contenteditable="true">{{item.userId}}</td>
<td contenteditable="true">{{item.name}}</td>
<td contenteditable="true">{{item.address}}</td>
</tr>
</table>
I am using the following contenteditable directive:
app.directive('contenteditable', ['$sce', function($sce) {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelController
link: function(scope, element, attrs, ngModel) {
}
};
}]);
The setup can be seen as: http://jsfiddle.net/cazfs31L/
Since the cells of the table are editable, I want to add validation to these cells to restrict the data that is being entered to them. The tricky part being I want to add validation based on the column header if possible. E.g. if the header is "Name" add different validation as compared to "Id" header/column.
I am just showing 3 columns in my demo but there can be more columns and more rows. Also, I don't want to use a textbox instead of cells here.
Any ideas how can I add validation here?