Skip to content

Commit

Permalink
Remove ability to add multiple 'Other'. Close #39
Browse files Browse the repository at this point in the history
  • Loading branch information
simonv3 committed Nov 2, 2016
1 parent 336ab4f commit 4961200
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
<div class="form-align-group" ng-if="option.type === 'other'">
<label for="{{ }}-other">Other: </label>
<input id="{{ }}-other" type="text" disabled/>
<a ng-click="removeOther()">
<i class="icon-cross"></i>
</a>
</div>
</li>
</ul>
<a class="option-control" ng-click="addOption()"><i class="icon-plus"></i> Add option</a>
<a class="option-control" ng-click="addOther()"><i class="icon-plus"></i> Add "other"</a>
<a class="option-control"
ng-click="addOther()"
ng-hide="otherAlreadyAdded">
<i class="icon-plus"></i> Add "other"
</a>
26 changes: 23 additions & 3 deletions client/js/manage/directives/add-question-with-options.ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ angular.module('quick-survey').directive('addQuestionWithOptions', function () {
existingOptions: '='
},
controller: function ($scope) {
$scope.otherAlreadyAdded = false;

if (!$scope.existingOptions) {
$scope.question.options = [{
'value': '',
'type': 'normal'
}];
} else {
$scope.existingOptions.forEach(function (option) {
if (option.type === 'other') {
$scope.otherAlreadyAdded = true;
}
});
}

$scope.remove = function (idx) {
Expand All @@ -24,10 +32,22 @@ angular.module('quick-survey').directive('addQuestionWithOptions', function () {
});
};

$scope.removeOther = function () {
if ($scope.otherAlreadyAdded) {
$scope.otherAlreadyAdded = false;
$scope.question.options = $scope.question.options.filter(function (option) {
return option.type !== 'other';
});
}
};

$scope.addOther = function () {
$scope.question.options.push({
'type': 'other'
});
if (!$scope.otherAlreadyAdded) {
$scope.otherAlreadyAdded = true;
$scope.question.options.push({
'type': 'other'
});
}
};
},
templateUrl: 'client/js/manage/directives/add-question-with-options.ng.html',
Expand Down

0 comments on commit 4961200

Please sign in to comment.