Skip to content

Commit a47276a

Browse files
author
daffl
committed
Renamed readme
1 parent 51db1af commit a47276a

File tree

1 file changed

+398
-0
lines changed

1 file changed

+398
-0
lines changed

readme.markdown

Lines changed: 398 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,398 @@
1+
The jQuery.dForm plugin generates HTML markup from JavaScript objects and [JSON](http://json.org)
2+
with a focus on HTML forms.
3+
4+
__Some things you can do:__
5+
6+
* use JavaScript and JSON instead of HTML markup since your page doesn't run without JS anyway
7+
* naturally 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+
* scaffold forms from business objects of your server side framework
10+
11+
## Get started:
12+
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
49+
* Visit the [jQuery.dForm Google Group](http://groups.google.com/group/jquery-dform)
50+
* Fork the project on [GitHub](http://github.com/daffl/jquery.dform/)
51+
* Follow [@daffl](http://twitter.com/daffl) on Twitter
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"></span>` tag to the element with the id my-div.
67+
Besides standard HTML tags the following core types are supported:
68+
69+
**container** `{ "type" : "container" }`
70+
Creates a \<div\> container (you can also use `{ "type" : "div" }`)
71+
72+
**text** `{ "type" : "text" }`
73+
Creates a text input field
74+
75+
**password** `{ "type" : "password" }`
76+
Creates a password input field
77+
78+
**submit** `{ "type" : "submit" }`
79+
Creates a submit button input element
80+
81+
**reset** `{ "type" : "reset" }`
82+
Creates a reset button input element
83+
84+
**hidden** `{ "type" : "hidden" }`
85+
Creates a hidden input element
86+
87+
**file** `{ "type" : "file" }`
88+
Create a file upload field
89+
90+
**radio** `{ "type" : "radio" }`
91+
Creates a radio button
92+
93+
**checkbox** `{ "type" : "checkbox" }`
94+
Creates a checkbox
95+
96+
**radiobuttons** `{ "type" : "radiobuttons" }`
97+
Creates a group of radiobuttons (uses options subscriber explained below)
98+
99+
**checkboxes** `{ "type" : "checkboxes" }`
100+
Creates a group of checkboxes
101+
102+
**number** `{ "type" : "number" }`
103+
Creates an HTML 5 number input field
104+
105+
**url** `{ "type" : "url" }`
106+
Creates an HTML 5 url input field
107+
108+
**tel** `{ "type" : "tel" }`
109+
Creates an HTML 5 phone number input field
110+
111+
**email** `{ "type" : "email" }`
112+
Creates an HTML 5 email input field
113+
114+
## Subscribers
115+
116+
Not everything can be solved using a custom type. Adding a class for example doesn't need to be implemented
117+
every time and this is where Subscribers come in. Subscribers are functions that will be called for the key they
118+
have been registered for when traversing the dForm object.
119+
120+
### Core subscribers
121+
122+
**type** *{String}*
123+
Besides looking up the correct Type Generator it also adds a dform specific class to the element using
124+
*$.dform.options.prefix* (*ui-dform-* by default) and the type name.
125+
126+
{
127+
"type" : "text"
128+
}
129+
130+
Generates:
131+
132+
<input type="text" class="ui-dform-text" />
133+
134+
**class** *{String}*
135+
Adds a class to the current element (instead of setting the attribute)
136+
137+
{
138+
"type" : "div",
139+
"class" : "the-div container"
140+
}
141+
142+
Generates:
143+
144+
<div class="ui-dform-div the-div container"></div>
145+
146+
**html/elements** *{String|Array|Object}*
147+
Based on the options it either sets the HTML string content of the current element or appends one or an array
148+
of dForm objects (the elements subscriber does the same but is kept for backwards compatibility).
149+
150+
{
151+
"type" : "div",
152+
"html" : "Div content"
153+
}
154+
155+
Generates:
156+
157+
<div class="ui-dform-div">Div content</div>
158+
159+
This subscriber can also be used to create nested objects by using one or an array of dForm objects:
160+
161+
{
162+
"type" : "div",
163+
"html" :
164+
[
165+
{
166+
"type" : "text"
167+
},
168+
{
169+
"type" : "div",
170+
"html" : {
171+
"type" : "p",
172+
"html" : "A paragraph"
173+
}
174+
}
175+
]
176+
}
177+
178+
Generates:
179+
180+
<div class="ui-dform-div">
181+
<input type="text" class="ui-dform-text" />
182+
<div class="ui-dform-div">
183+
<p class="ui-dform-p">A paragraph</p>
184+
</div>
185+
</div>
186+
187+
**value** *{String|Function}*
188+
Sets the value of the element using .val()
189+
190+
{
191+
"type" : "text",
192+
"value" : "Text content"
193+
}
194+
195+
Generates:
196+
197+
<input type="text" value="Text content" />
198+
199+
**css** {Object}
200+
Sets CSS properties on an element:
201+
202+
{
203+
"type" : "div",
204+
"css" : {
205+
"background-color" : "#FF0000",
206+
"display" : "none"
207+
}
208+
}
209+
210+
Generates:
211+
212+
<div class="ui-dform-div" style="background-color: #FF0000; display: none;"></div>
213+
214+
**options** *{Object}*
215+
Generates a list of options from a value to text (or dForm Object) mapping for elements of type *select*, *radiobuttons*
216+
or *checkboxes*.
217+
218+
> *Note:* The Google Chrome JavaScript engine V8 orders object keys that can be cast to numbers by their value and
219+
> not by the order of their definition.
220+
221+
{
222+
"type" : "select",
223+
"options" : {
224+
"us" : "USA",
225+
"ca" : "Canada",
226+
"de" : {
227+
"selected" : "selected",
228+
"html" : "Germany"
229+
}
230+
}
231+
}
232+
233+
Generates:
234+
235+
<select>
236+
<option value="us">USA</option>
237+
<option value="ca">Canada</option>
238+
<option value="de" selected="selected">Germany</option>
239+
</select>
240+
241+
You can also use options on *checkboxes* and *radiobuttons* which will create a list of *checkbox*
242+
or *radio* elements:
243+
244+
{
245+
"type" : "checkboxes",
246+
"options" : {
247+
"newsletter" : "Receive the newsletter",
248+
"terms" : "I read the terms of service",
249+
"update" : "Keep me up to date on new events"
250+
}
251+
}
252+
253+
Generates:
254+
255+
// TODO
256+
257+
**caption** *{String|Object}*
258+
Adds a caption to the element. The type used for it depends on the element type:
259+
* A *legend* on *fieldset* elements
260+
* A *label* next to *radio* or *checkbox* elements
261+
* A *label* before any other element
262+
If the element has its id set the for attribute of the label will be set as well.
263+
264+
{
265+
"type" : "text",
266+
"name" : "username",
267+
"id" : "username",
268+
"caption" : "Enter your username"
269+
}
270+
271+
Generates:
272+
273+
<label for="username" class="ui-dform-label">Enter your username</label>
274+
<input type="text" class="ui-dform-text" id="username" />
275+
276+
For fieldsets:
277+
278+
{
279+
"type" : "fieldset",
280+
"caption" : "Address"
281+
}
282+
283+
Generates:
284+
285+
<fieldset class="ui-dform-fieldset">
286+
<legend type="ui-dform-legend">Address</label>
287+
</fieldset>
288+
289+
**url**
290+
TODO
291+
292+
### Special subscribers
293+
294+
Currently there are two types of special subscribers
295+
296+
**\[pre\]** *{Object}*
297+
Functions registered with this name will be called before any processing occurs and get the original options passed.
298+
299+
**\[post\]** *{Object}*
300+
Functions registered with this name will be called after all processing is finished and also get the original
301+
options passed.
302+
303+
## Extend the plugin
304+
305+
## Plugin methods
306+
307+
Default
308+
309+
run
310+
append
311+
attr({Object})
312+
ajax
313+
314+
## jQuery UI
315+
316+
## Form plugin
317+
318+
## Validation plugin
319+
320+
## jQuery Globalize
321+
322+
## Changelog
323+
324+
### 0.2.0
325+
326+
* Full QUnit test suite
327+
* Improved documentation
328+
* Changed API
329+
* Added deferred loading of subscribers
330+
331+
### 0.1.4
332+
333+
* Merged pull request [#30](https://github.com/daffl/jquery.dform/pull/30): Wrap 'type' as an array so it doesn't break jQuery 1.7.1's $.inArray() when running in IE8
334+
* Added first QUnit tests
335+
* Fixed issue #22 with jQuery UI accordion causing problems with captions
336+
* Removed placeholder plugin. Use HTML 5 placeholders or the jQuery [placeholder plugin](https://github.com/danielstocks/jQuery-Placeholder)
337+
* Updated documentation engine to DocumentJS and build system to StealJS
338+
* Merged pull request [#19](https://github.com/daffl/jquery.dform/pull/19) and [#20](https://github.com/daffl/jquery.dform/pull/20), support to set up a validate options for validate() in "form" type
339+
* Merged pull request [#26](https://github.com/daffl/jquery.dform/pull/26) to support HTML 5 input types
340+
* Added simple getting started example
341+
342+
### 0.1.3
343+
344+
* Created some public [JSFiddles for trying the plugin](http://jsfiddle.net/user/Daff/fiddles)
345+
* Created [jQuery.dForm Google Group](http://groups.google.com/group/jquery-dform)
346+
* Added <form> type, unified <buildForm> usage
347+
* Fixed [issue #14](https://github.com/daffl/jquery.dform/issues/closed#issue/14), setting type attribute properly in IE
348+
* Added <getValueAt>
349+
* Added <i18n> support using the [jQuery globalize](https://github.com/jquery/jquery-global) plugin
350+
* Fixed minor bugs in dform plugins
351+
352+
### 0.1.2
353+
354+
* Added <dformAttr> to add HTML attributes to elements
355+
* Moved <placeholder> into a separate plugin
356+
* Added <reset> button type
357+
* Added dynamic form definition loading by passing a URL to the <buildForm> plugin function
358+
* Added <ajax> subscriber using the <jQuery form plugin at http://jquery.malsup.com/form>
359+
* Added the <defaultType> method to create any HTML element without having to register a type
360+
* Improved build process
361+
362+
### 0.1.1
363+
364+
* Separated type and subscriber functions
365+
* Added types <file>, <container>, <hidden>, <accordion>, <checkboxes> and <radiobuttons>
366+
* Added auto class generation based on element type
367+
* Finished jQuery UI <accordion> and unified with <tabs> usage
368+
* Switched documentation to <Natualdocs at http://naturaldocs.org>
369+
* Added build.xml for generating documentation and minifying JavaScript
370+
371+
### 0.1
372+
373+
* Initial release
374+
375+
## License
376+
377+
Copyright (C) 2012 [David Luecke](daff@neyeon.com), [http://daffl.github.com/jquery.dform]
378+
379+
The MIT license:
380+
381+
Permission is hereby granted, free of charge, to any person obtaining
382+
a copy of this software and associated documentation files (the
383+
"Software"), to deal in the Software without restriction, including
384+
without limitation the rights to use, copy, modify, merge, publish,
385+
distribute, sublicense, and/or sell copies of the Software, and to
386+
permit persons to whom the Software is furnished to do so, subject to
387+
the following conditions:
388+
389+
The above copyright notice and this permission notice shall be
390+
included in all copies or substantial portions of the Software.
391+
392+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
393+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
394+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
395+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
396+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
397+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
398+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)