-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-dynamicforms.html
73 lines (70 loc) · 4.38 KB
/
angular-dynamicforms.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script src="angular-dynamicforms.js"></script>
<title>Dynamic Forms</title>
</head>
<body ng-app="myApp" ng-controller="MyCtrl">
<div class="container-fluid">
<div class="row-fluid">
<div class="span4">
<h3 ng-click="debugQuestions = !debugQuestions">Questions</h3>
<input type="text" ng-model="newQuestion.label" placeholder="questionLabel">
<select ng-model="newQuestion.answer.type" ng-change="setDefaultOptions()">
<option value="text">Texte</option>
<option value="textarea">Texte long</option>
<option value="radio">Radio</option>
<option value="checkbox">Checkboxes</option>
</select>
<ul ng-show="newQuestion.answer.type == 'radio' || newQuestion.answer.type == 'checkbox'">
<li ng-click="addOption()">(+)</li>
<li ng-repeat="option in newQuestion.answer.options">
<input type="text" ng-model="option.label" placeholder="optionLabel">
<input type="text" ng-model="option.value" ng-hide="newQuestion.answer.type == 'checkbox'" placeholder="optionValue">
</li>
</ul>
<input type="submit" ng-click="addQuestion()">
<pre ng-show="debugQuestions">{{model.questions | json}}</pre>
</div>
<div class="span8">
<h3>Formulaire</h3>
<ol>
<li ng-repeat="question in model.questions">{{question.label}}
<ul class="unstyled">
<li>
<div ng-switch="question.answer.type">
<input type="text" ng-switch-when="text" ng-model="question.answer.value" validate="question.answer.validate" my-directive>
<div ng-switch-when="radio">
<label class="radio inline" ng-repeat="option in question.answer.options">
<input type="radio" name="question_{{question.id}}" value="{{option.value}}" ng-model="question.answer.value">
{{option.label}}
</label>
</div>
<div ng-switch-when="checkbox">
<label class="checkbox" ng-repeat="option in question.answer.options">
<input type="checkbox" ng-true-value="{{option.value}}" ng-model="question.answer.options[$index].value" ng-change="buildCheckboxAnswer(question)">
{{option.label}}
</label>
<input ng-list ng-model="question.answer.value" ng-change="setCheckboxAnswers(question)">
</div>
<textarea ng-switch-when="textarea" ng-model="question.answer.value"></textarea>
</div>
</li>
</ul>
</li>
</ol>
</div>
<div class="span4" style="position: absolute; top: 0; right: 0">
<h3 ng-click="debugAnswers = !debugAnswers">Réponses</h3>
<pre ng-show="debugAnswers">{{answers | json}}</pre>
</div>
</div>
</div>
</body>
</html>