forked from corinis/jsForm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-connect.html
69 lines (63 loc) · 2.26 KB
/
sample-connect.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
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/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: true, // 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,
});
$(details).jsForm("connect", $("#additional"));
$("#show").click(function() {
// show the json data
alert(JSON.stringify($("#details").jsForm("get"), null, " "));
});
});
</script>
</head>
<body>
<h1>Connect two Forms into one</h1>
<i>In this example, the form is split into two dom elements, with no direct connection, but they are filled with one jsForm call and also put together correctly.</i>
<div id="details">
Name: <input name="data.name"/><br/>
<input type="checkbox" name="data.active"/> active<br/>
Age: <input name="data.age" class="number"/><br/>
<select name="data.state">
<option value="VISIBLE">visible</option>
<option value="IMPORTANT">important</option>
<option value="HIDDEN">hidden</option>
</select>
<fieldset>
<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"/>
</div>
<h2>The second part</h2>
<div id="additional">
<textarea name="data.description"></textarea><br/>
<fieldset>
<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>
</body>
</html>