-
Notifications
You must be signed in to change notification settings - Fork 6
/
dynamicForms.html
161 lines (158 loc) · 6.33 KB
/
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="panel panel-primary animated fadeInLeft">
<div class="panel-heading">
<h3 class="panel-title">Form Builder</h3>
</div>
<div class="panel-body" style="height:400px;overflow:auto;">
<form class="form" ng-submit="saveField()">
<div class="form-group">
<label for="newField-name">Field Name:</label> <input type="text"
class="form-control" id="newField-name" ng-model="newField.name" ng:required>
</div>
<div class="form-group">
<label>Required: <input
type="checkbox" id="newField-required"
ng-model="newField.required">
</label>
</div>
<div class="form-group">
<label for="newField-order">Order Weight:</label> <input
class="form-control" type="number" id="newField-order" ng-model="newField.order"
value="0" ng-required placeholder="0">
</div>
<div class="form-group">
<label for="newField-type">Field Type:</label> <select
class="form-control" id="newField-type" ng-model="newField.type" ng-required>
<option value="text" selected>Text</option>
<option value="radio">Radio Buttons</option>
<option value="select">Drop Menu (Select)</option>
<option value="multiple">Multi-Select</option>
<option value="checkbox">Toggle (Checkbox)</option>
<option value="checkboxes">Checkboxes</option>
<option value="textarea">Paragraph(s)</option>
<option value="number">Number</option>
<option value="url">Url</option>
<option value="phone">Phone</option>
<option value="email">Email</option>
<option value="header">Heading</option>
</select>
</div>
<ng-switch on="typeSwitch(newField.type)">
<div ng-switch-default class="form-group">
<label for="newField-placeholder">Instructions:</label> <input
class="form-control" type="text" id="newField-placeholder"
ng-model="newField.placeholder">
</div>
<fieldset ng-switch-when="multiple">
<legend>
<a class="btn btn-primary btn-xs" ng-click="addOption()">Add Option</a>
</legend>
<div class="panel panel-primary"
ng-repeat="option in newField.options|orderBy:'order'">
<div class="panel-body">
<b><i>Option:</i></b>
<button class="btn btn-danger btn-xs"
ng-click="splice(option, newField.options)">Remove</button>
<div class="form-group">
Name: <input class="form-control" type="text" ng-model="option.name"
ng-required>
Value: <input class="form-control" type="text"
ng-model="option.value">
Order: <input class="form-control" type="number"
ng-model="option.order">
</div>
</div>
</div>
</fieldset>
<span ng-switch-when="checkbox"></span> <span
ng-switch-when="header"></span> </ng-switch>
<div>
<input class="btn btn-warning"type="submit" value="Create New Field">
</div>
</form>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-primary animated fadeInRight" >
<div class="panel-heading">
<h3 class="panel-title">Form Preview</h3>
</div>
<div class="panel-body" style="height:400px;overflow:auto;">
<div ng-repeat="field in fields | orderBy:'order'">
<ng-switch on="field.type">
<h3 ng-switch-when="header" class="animated fadeInRight">
{{field.order}} {{field.name}}
<button class="btn btn-warning btn-xs" ng-click="editField(field)">Edit</button>
<button class="btn btn-danger btn-xs" ng-click="splice(field, fields)">Remove</button>
</h3>
<div ng-switch-default class="input {{field.type}}"
ng-class="field.required && 'required'">
<div class="form-group">
<label>
{{field.order}} . {{field.name}}
<button class="btn btn-warning btn-xs" ng-click="editField(field)">Edit</button>
<button class="btn btn-danger btn-xs" ng-click="splice(field, fields)">Remove</button>
</label>
<ng-switch on="field.type">
<input class="form-control animated fadeInRight" ng-switch-default
type="{{field.type}}" ng-model="field.value"
ng-bind-attr="{required:'{{field.required}}'}"
value="{{field.value}}" placeholder="{{field.placeholder}}">
<input ng-switch-when="checkbox" type="checkbox" class="animated fadeInRight"
ng-model="field.value" value="{{field.value}}" id="field"
placeholder="{{field.instructions}}">
<textarea class="form-control animated fadeInRight"
ng-switch-when="textarea" ng-model="field.value"
placeholder="{{field.instructions}}">{{field.value}}
</textarea>
<select class="form-control animated fadeInRight"
ng-switch-when="select" ng-model="field.value">
<option ng-repeat="option in field.options"
value="{{option.value}}">{{option.name}}
</option>
</select>
<select class="form-control animated fadeInRight"
ng-switch-when="multiple" ng-model="field.value" multiple>
<option ng-repeat="option in field.options"
value="{{option.value}}">{{option.name}}
</option>
</select>
<fieldset ng-switch-when="radio">
<label ng-repeat="option in field.options">
<input class="animated fadeInRight"
type="radio" ng-model="field.value" value="{{option.value}}">
{{option.name}}
</label>
</fieldset>
<fieldset ng-switch-when="checkboxes">
<label ng-repeat="option in field.options">
<input class="animated fadeInRight"
type="checkbox" ng-model="field.value[tokenize(option.name)]"
value="{{option.value}}"> {{option.name}}
</label>
</fieldset>
</ng-switch>
</div>
</div>
</ng-switch>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-warning animated fadeInUp">
<div class="panel-heading">
<h3 class="panel-title">JSON Data</h3>
</div>
<div class="panel-body" style="height:100px;overflow:auto;">
<pre>{{fields}}</pre>
</div>
</div>
</div>
</div>
</div>