Could you please specify the number of choices you would like to display? For example, if the user enters 10, then 10 choices will be displayed. I have been trying to implement this functionality, but it keeps resulting in a memory error.
dynamicform.jsp
<!DOCTYPE html>
<html ng-app="dynamicFieldsPlugin">
<head>
<!-- <link data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0c01011a1d1a1c0f1e2e5d405d405c">[email protected]</a>" data-semver="3.3.2" rel="stylesheet" href="themes/bootstrap.min.css" />
<script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31535e5e45424543504171021f021f03">[email protected]</a>" data-semver="3.3.2" src="js/bootstrap.min.js"></script>
<script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cca6bdb9a9beb58cfee2fde2ff">[email protected]</a>" data-semver="2.1.3" src="js/jquery-2.1.3.min.js"></script>
-->
Dynamic Form Fields Creation Plugin
<label for="choice" ng-show="showChoiceLabel(choice)">Choices</label>
<label>How many Choices you want?</label>
<input type="text" ng-modal="{{nochoices}}" name="" value="{{nochoices}}">
<button ng-show="showAddChoice(choice)" ng-click="addNewChoiceno(nochoices)">Add Choice</button>
<div class="form-group" data-ng-repeat="choice in choices">
<br/><br/>
<!-- <button ng-show="showAddChoice(choice)" ng-click="addNewChoice()">Add Choice</button> -->
<button ng-click="removeNewChoice()">Remove Choice</button>
<input type="text" ng-modal="{{choice.name}}" name="" placeholder="Enter a restaurant name" value="{{choice.id}}">
</div>
</div>
<!--jQuery Scripts -->
<script src="js/angularjs/1.4.8/app.js"></script>
</body>
app.js
var app = angular.module("dynamicFieldsPlugin", []);
app.controller("dynamicFields", function($scope) {
$scope.nochoices = 10;
$scope.choices = [{id: 'choice1', name: 'choice1'}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
$scope.choices.push({'id' : 'choice' + newItemNo, 'name' : 'choice' + newItemNo});
};
$scope.addNewChoiceno = function(nochoices) {
for(var i=$scope.choices.length;i<nochoices+$scope.choices.length;i++){
$scope.choices.push({'id' : 'choice' + i, 'name' : 'choice' + i});
}
$scope.choices.length=$scope.choices.length+nochoices;
};
$scope.removeNewChoice = function() {
var newItemNo = $scope.choices.length-1;
if ( newItemNo !== 0 ) {
$scope.choices.pop();
}
};
$scope.showAddChoice = function(choice) {
return choice.id === $scope.choices[$scope.choices.length-1].id;
};
});
error
out of memory