-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsample-conditional.html
74 lines (71 loc) · 2.65 KB
/
sample-conditional.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
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="src/jquery.jsForm.js"></script>
<script>
$(function(){
// some json data
var jsonData = {
name: "TestName", // standard inputs
description: "long Description\nMultiline", // textarea
links: [{href:'http://www.gargan.org',description:'Gargan.org'},{href:'http://www.github.com',description:'GitHub'}], // lists
active: false, // checkbox
state: "VISIBLE", // selects (enums)
age: 45, // number
quips: ["Don't left school interfere with your education!", "Can you repeat the question? I was thinking about cookies.", "In my house I'm the boss, my wife is just the decision maker."]
};
// initialize the form, prefix is optional and defaults to data
$("#details").jsForm({
data:jsonData
});
$("#show").click(function() {
// show the json data
alert(JSON.stringify($("#details").jsForm("get"), null, " "));
});
$("#eval").click(function(){
var obj = $("#details").jsForm("get");
$("#details").jsForm("fill", obj);
});
});
</script>
<style>
/* conditionals are always invisible per default */
.conditional { display: none }
</style>
</head>
<body>
<h1>Conditional Form Test</h1>
<i>This form is all about sho/hiding parts of the dom based on data and input</i>
<div id="details">
Name: <input name="data.name"/><br/>
<input type="checkbox" name="data.active"/> activate Age<br/>
<div class="conditional" data-show="data.active">
Age: <input name="data.age" class="number"/><br/>
</div>
<textarea name="data.description" class="conditional" data-hide="data.active"></textarea><br/>
<select name="data.state">
<option value="VISIBLE">visible</option>
<option value="IMPORTANT">important</option>
<option value="HIDDEN">hidden</option>
</select>
<fieldset class="conditional" data-show="data.active data.name">
<i>links are only shown if name or active is set</i>
<legend>Links</legend>
<ul class="collection" data-field="data.links">
<li><span class="field">links.description</span> Link: <input name="links.href"/> <button class="delete">x</button></li>
</ul>
</fieldset>
<button class="add" data-field="data.links">add a link</button><br/>
Additional field: <input name="data.addedField"/>
<i>Fill something in the addional field and apply conditionals to see quips</i>
<fieldset class="conditional" data-show="data.addedField">
<legend>Quips</legend>
<ul class="collection" data-field="data.quips">
<li><input name="quips."/></li>
</ul>
<button class="add" data-field="data.quips">add a quip</button><br/>
</fieldset>
</div>
<button id="show">Show Object</button><button id="eval">Apply Conditionals</button>
</body>
</html>