@@ -27,8 +27,9 @@ EntriesController = ($scope, $state, Restangular, $stateParams, Alertify, Errors
2727
2828 $scope.initAssociationField = (field)->
2929 if field.type == 'Kms::HasManyField'
30- $scope.entry.values[field.liquor_name] = _.filter $scope[field.liquor_name], (element)->
31- _.contains $scope.entry.values[field.liquor_name], element.id.toString()
30+ fieldEntries = _.map $scope.entry.values[field.liquor_name], (entryId)->
31+ _.find $scope[field.liquor_name], { 'id': parseInt(entryId) }
32+ $scope.entry.values[field.liquor_name] = _.compact fieldEntries
3233 else
3334 $scope.entry.values[field.liquor_name] = _.find $scope[field.liquor_name], (element)->
3435 $scope.entry.values[field.liquor_name] == element.id.toString()
@@ -65,16 +66,16 @@ EntriesController = ($scope, $state, Restangular, $stateParams, Alertify, Errors
6566 if $scope.entry.slug
6667 fd.append("entry[slug]", $scope.entry.slug)
6768 for key, value of $scope.entry.values
68- continue if value == undefined
69- if value
69+ # continue if value == undefined
70+ unless _.isEmpty( value)
7071 if value.constructor.name == 'Array'
7172 for element in value
7273 id = if element.constructor.name == 'Object' then element.id else element
7374 fd.append("entry[values][#{key}][]", id)
7475 else if value.constructor.name != 'Object'
7576 fd.append("entry[values][#{key}]", value || '')
7677 else
77- fd.append("entry[values][#{key}]", value || '')
78+ fd.append("entry[values][#{key}]", if value? then value else '')
7879 $scope.entry.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
7980 $state.go('models.entries', modelId: $scope.model.id)
8081 ,(response)->
0 commit comments