I'm trying to implement checklist statuses inside editable row base on xeditable examples. Unfortunately list doesn't work. It display current statuses when row is disabled, and all options when it's in edit mode, but selected statuses are not checked. I don't know how to properly connect checkboxes with current $scope.user.statuses object..
script:
var app = angular.module("app", ["xeditable"]);
app.run(function(editableOptions) {
editableOptions.theme = 'bs3';
});
app.controller('Ctrl', function($scope, $filter, $http) {
$scope.users = [
{id: 1, name: 'user1', statuses: [2,3]},
{id: 2, name: 'user2', statuses: [1]},
{id: 3, name: 'user3', statuses: [1,2,3,4]}
];
$scope.statuses = [
{value: 1, text: 'status1'},
{value: 2, text: 'status2'},
{value: 3, text: 'status3'},
{value: 4, text: 'status4'}
];
$scope.showStatus = function(user) {
var selected = [];
angular.forEach($scope.statuses, function(s) {
if (user.statuses.indexOf(s.value) >= 0) {
selected.push(s.text);
}
});
return selected.length ? selected.join(', ') : 'Not set';
};
$scope.saveUser = function(data, id) {
angular.extend(data, {id: id});
return $http.post('/saveUser', data);
};
});
html
<div ng-app="app" ng-controller="Ctrl">
<table class="table table-bordered table-hover table-condensed">
<tr style="font-weight: bold">
<td style="width:30%">Name</td>
<td style="width:40%">Status</td>
<td style="width:30%">Edit</td>
</tr>
<tr ng-repeat="user in users">
<td>
<!-- editable username (text with validation) -->
<span editable-text="user.name" e-name="name" e-form="rowform" e-required>
{{ user.name || 'empty' }}
</span>
</td>
<td>
<span editable-checklist="user.statuses" e-form="rowform" e-ng-options="s.value as s.text for s in statuses">
{{ showStatus(user) }}
</span>
</td>
<td style="white-space: nowrap">
<!-- form -->
<form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == user">
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
save
</button>
<button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
cancel
</button>
</form>
<div class="buttons" ng-show="!rowform.$visible">
<button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
</div>
</td>
</tr>
</table>
</div>
working example is here http://jsfiddle.net/NfPcH/6493/
Thanks.