1
- The jQuery.dForm plugin allows you to create your HTML forms programmatically as JavaScript objects or
2
- as [ JSON ] ( http://json.org ) . Let the browser do the work and generate JavaScript enhanced forms without hassle.
1
+ The jQuery.dForm plugin generates HTML markup from JavaScript objects and [ JSON ] ( http://json.org )
2
+ with a focus on HTML forms.
3
3
4
- ### You should try this plugin if you want to
4
+ __ Some things you can do: __
5
5
6
- * write JavaScript instead of HTML markup since your page doesn't run without JS anyway
7
- * manage all your form related jQuery plugins in a unified way
8
- * have an easy way to include jQuery UI elements and JavaScript validation
6
+ * use JavaScript and JSON instead of HTML markup since your page doesn't run without JS anyway
7
+ * generate JavaScript enhanced markup with your own extensions and custom types
8
+ * have an easy way to include jQuery UI elements and JavaScript validation (both supported out of the box)
9
9
* scaffold forms from business objects of your server side framework
10
10
11
11
## Get started:
12
12
13
- All examples are hosted on [ JSFiddle] ( http://jsfiddle.net ) . Feel free to play around, fork and comment:
14
-
15
- <iframe style="width: 90%; height: 450px" src="http://jsfiddle.net/Daff/yREkc/embedded/js,html,result"
16
- allowfullscreen="allowfullscreen" frameborder="0">
17
- </iframe >
18
-
19
- ## How to get it:
20
-
21
- [ Download] ( http://github.com/downloads/daffl/jquery.dform/jquery.dform-0.1.4.tar.gz ) the latest package (0.1.4(
22
-
23
- Clone the current master on [ GitHub] ( http://github.com/daffl/jquery.dform/ )
24
-
25
-
26
- ## How to get involved:
27
-
13
+ [ Download] ( http://github.com/downloads/daffl/jquery.dform/jquery.dform-0.1.4.tar.gz )
14
+ the latest version 0.2.0 (6 Kb minified)
15
+
16
+ Then try this JavaScript snipped:
17
+
18
+ $("#myform").dform({
19
+ "action" : "index.html",
20
+ "method" : "get",
21
+ "html" :
22
+ [
23
+ {
24
+ "type" : "p",
25
+ "html" : "You must login"
26
+ },
27
+ {
28
+ "name" : "username",
29
+ "id" : "txt-username",
30
+ "caption" : "Username",
31
+ "type" : "text",
32
+ "placeholder" : "E.g. user@example.com"
33
+ },
34
+ {
35
+ "name" : "password",
36
+ "caption" : "Password",
37
+ "type" : "password"
38
+ },
39
+ {
40
+ "type" : "submit",
41
+ "value" : "Login"
42
+ }
43
+ ]
44
+ });
45
+
46
+ __ Learn more:__
47
+
48
+ * Check out the JSFiddle examples or the get started page for more examples
28
49
* Visit the [ jQuery.dForm Google Group] ( http://groups.google.com/group/jquery-dform )
29
- * Fork the project on [ GitHub] ( http://github.com/daffl/jZquery .dform/ )
50
+ * Fork the project on [ GitHub] ( http://github.com/daffl/jquery .dform/ )
30
51
* Follow [ @daffl ] ( http://twitter.com/daffl ) on Twitter
31
-
32
-
33
-
34
-
35
- # Types
36
-
37
- # Subscribers
38
-
39
- * Subscribers are the core concept of the jQuery.dForm.
40
- *
41
- * They are functions, that will be called when traversing the options
42
- * passed to the plugin.
43
- * You can use the already existing subscribers as well as register your own.
44
- *
45
- * The plugin has three different types of subscribers
46
- *
47
- * Types - For creating a new element of the given type.
48
- * Subscribers - Which will be called when the name they are registered with
49
- * appears in the options given to the plugin and after the type element has been added to the DOM.
50
- * Special subscribers - Will be called on special events.
51
- *
52
- * Currently there are two types of special subscribers
53
- * * [ pre] - Functions registered with this name will be called before any processing occurs.
54
- * * [ post] - Functions registered with this name will be called after all processing is finished.
55
- *
56
- * Example:
57
- * (start code)
58
- * $("#myform").buildForm({
59
- * "name" : "textfield",
60
- * "type" : "text",
61
- * "id" : "testid",
62
- * "value" : "Testvalue",
63
- * "caption" : "Label for textfield"
64
- * });
65
- * (end)
66
- *
67
- * The above JavaScript snippet will do the following
68
- *
69
- * - Look for a type subscriber called <text >, which creates an input field with the type text or, if
70
- * there is no matching type call the <defaultType > function which creates a HTML tag of the given type.
71
- * - Add all attributes as HTML attributes to the input element that don't have a
72
- * subscriber registered (which are name and id)
73
- * - Add the new element to the DOM (append to #myform).
74
- * - Run the <type > subscriber which adds the auto generated class name ui-dform-text to the input field
75
- * - Run the <value > subscriber which sets the value of this form element
76
- * - Run the <caption > subscriber which adds a label before the textfield
77
- *
78
- * Read in the <Extensions > chapter, how you can extend the dForm Plugin with your own
79
- * types and subscribers.
80
- *
81
- * This page will list the basic <Types > and <Subscribers > that are
82
- * supported by the plugin as well as examples for using them.
52
+ * Read on in this documentation
53
+
54
+ ## Types
55
+
56
+ Type Generators are functions that return a new jQuery DOM object for a specific type. If there is no Type Generator
57
+ with a given name, a basic HTML element with that tag name will be created. Every other key in the JavaScript or JSON object
58
+ you pass will be used as an HTML attribute. An exception is, if there is a Subscriber registered for that ke (more about
59
+ this in the next section). A plugin call like this:
60
+
61
+ $('#my-div').dform({
62
+ type : "span",
63
+ id : "the-span"
64
+ });
65
+
66
+ Will append an empty \< span id="the-span"\> tag to the element with the id my-div.
67
+ Besides standard HTML tags the following core types are supported:
68
+
69
+ * __ container__ : Creates a \< div\> container (you can also use { type : 'div' })
70
+ * __ text__ : Creates a text input field
71
+ * __ password__ : Creates a password input field
72
+ * __ submit__ : Creates a submit button input element
73
+ * __ reset__ : Creates a reset button input element
74
+ * __ hidden__ : Creates a hidden input element
75
+ * __ file__ : Create a file upload field
76
+ * __ radio__ : Creates a radio button
77
+ * __ checkbox__ : Creates a checkbox
78
+ * __ radiobuttons__ : Creates a group of radiobuttons (uses options subscriber explained below)
79
+ * __ checkboxes__ : Creates a group of checkboxes
80
+ * __ number__ : Creates an HTML 5 number input field
81
+ * __ url__ : Creates an HTML 5 url input field
82
+ * __ tel__ : Creates an HTML 5 phone number input field
83
+ * __ email__ : Creates an HTML 5 email input field
84
+
85
+ ## Subscribers
86
+
87
+ Not everything can be solved using a custom type. Adding a class for example doesn't need to be implemented
88
+ every time and this is where Subscribers come in. Subscribers are functions that will be called for the key they
89
+ have been registered for when traversing the object that has been passed to the plugin.
90
+
91
+ ### Core subscribers
92
+
93
+ * class:
94
+ * html:
95
+ * elements:
96
+ * value:
97
+ * css:
98
+ * options:
99
+ * caption:
100
+ * url:
101
+ * type:
102
+
103
+ ### Special subscribers
104
+
105
+ Currently there are two types of special subscribers
106
+
107
+ * __ \[ pre\] __ Functions registered with this name will be called before any processing occurs.
108
+ * __ \[ post\] __ Functions registered with this name will be called after all processing is finished.
109
+
110
+
111
+ ### Processing example:
112
+
113
+ Here is a quick example walkthrough:
114
+
115
+ $("#myform").dform({
116
+ "name" : "textfield",
117
+ "type" : "text",
118
+ "id" : "testid",
119
+ "value" : "Testvalue",
120
+ "caption" : "Label for textfield"
121
+ });
122
+
123
+ Which will do the following:
124
+
125
+ * Look for a Type Generator with the name __ text__ , which creates an input field with the type text
126
+ * Add the HTML attributes to the input element that don't have a subscriber registered (which are __ name__ and __ id__ )
127
+ * Add the new element to the DOM (append to #myform)
128
+ * Run the __ type__ subscriber which adds the auto generated class name _ ui-dform-text_ to the input field
129
+ * Run the __ value__ subscriber which sets the value of this form element
130
+ * Run the __ caption__ subscriber which adds a label before the textfield
83
131
84
132
# Plugin support
85
133
@@ -91,7 +139,6 @@ Clone the current master on [GitHub](http://github.com/daffl/jquery.dform/)
91
139
92
140
## jQuery Globalize
93
141
94
-
95
142
# Changelog
96
143
97
144
### 0.2.0
0 commit comments