@@ -11,7 +11,7 @@ __Some things you can do:__
11
11
## Get started
12
12
13
13
[ Download the latest version 0.2.0] ( https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-0.2.0.min.js )
14
- (6 Kb minified)
14
+ (~ 7 Kb minified)
15
15
16
16
Include it in your jQuery powered page and try this:
17
17
@@ -160,24 +160,12 @@ Now generates
160
160
161
161
## Subscribers
162
162
163
- Not everything can be solved using a custom type. Adding a class, for example, doesn't need to be implemented
164
- for every type and this is where Subscribers come in. Subscribers are functions that will be called for the key they
165
- have been registered for when traversing the dForm object .
163
+ While type generators are being used to generate a base element for the given type, subscribers attach to
164
+ certain attributes in the options object. When traversing the object all subscribers registered for the
165
+ current key will be executed on the current element .
166
166
167
167
### Core subscribers
168
168
169
- ** type** * {String}* <br />
170
- Besides looking up the correct Type Generator it also adds a dform specific class to the element using
171
- ` $.dform.options.prefix ` (* ui-dform-* by default) and the type name.
172
-
173
- {
174
- "type" : "text"
175
- }
176
-
177
- Generates:
178
-
179
- <input type="text" class="ui-dform-text" />
180
-
181
169
** class** * {String}* <br />
182
170
Adds a class to the current element (instead of setting the attribute) using [ .addClass()] ( http://api.jquery.com/addClass ) .
183
171
@@ -342,6 +330,20 @@ Generates:
342
330
<legend type="ui-dform-legend">Address</label>
343
331
</fieldset>
344
332
333
+ ** type** * {String}* <br />
334
+ Besides looking up the correct Type Generator it also adds a dform specific class to the element using
335
+ ` $.dform.options.prefix ` (* ui-dform-* by default) and the type name.
336
+
337
+ {
338
+ "type" : "text"
339
+ }
340
+
341
+ Generates:
342
+
343
+ <input type="text" class="ui-dform-text" />
344
+
345
+ Set ` $.dform.options.prefix = false; ` if you don't want any classes being added.
346
+
345
347
### Add your own
346
348
347
349
It is easy to add your own subscribers. Similar to a type generator you just pass the key name you want to subscribe
@@ -383,15 +385,17 @@ Functions registered with this name will be called before any processing occurs
383
385
Functions registered with this name will be called after all processing is finished and also get the original
384
386
options passed.
385
387
386
- ## Plugin methods
388
+ ## Plugin
389
+
390
+ ### jQuery plugin methods
387
391
388
392
The __ dform__ plugin function follows the jQuery plugin convention of taking an options object or a
389
393
method name as the first parameter to call different methods:
390
394
391
- ** $(form).dform(options, converter)** * {Object}* * \[ {String}\] * <br />
395
+ ** $(form).dform(options \[ , converter\] )** * {Object}* * {String}* <br />
392
396
Append the dForm object to each selected element. If the element is of the same type (e.g. if you are appending
393
397
a ` type : 'form' ` on a ` <form> ` or if no type has been given) run the subscribers and
394
- add the attributes on the current element.
398
+ add the attributes on the current element. Optionally use a converter with a given name.
395
399
396
400
** $(form).dform('run', options)** * {Object}* <br />
397
401
Run all subscribers from a given dForm object on the selected element(s).
@@ -400,16 +404,64 @@ Run all subscribers from a given dForm object on the selected element(s).
400
404
Run a subscriber with a given name and options on the selected element(s) using a specific type.
401
405
Usually used internally.
402
406
403
- ** $(form).dform('append', options, converter)** * {Object}* * \[ {String}\] * <br />
407
+ ** $(form).dform('append', options \[ , converter\] )** * {Object}* * {String}* <br />
404
408
Append a dForm element to each selected element. Optionally using a converter with the
405
409
given name.
406
410
407
411
** $(form).dform('attr', options)** * {Object}* <br />
408
412
Set each attribute from the options object that doesn't have a corresponding subscriber registered.
409
413
410
- ** $(form).dform('ajax', params, success, error)** * {Object|String}* * {Function}* * {Function}* <br />
414
+ ** $(form).dform('ajax', params \[ , success\] \[ , error\] )** * {Object|String}* * {Function}* * {Function}* <br />
411
415
Load a form definition using Ajax.
412
416
417
+ ### Static functions
418
+
419
+ ** $.keySet(object)** * {Object}* <br />
420
+ Return an array of the objects keys.
421
+
422
+ ** $.withKeys(object, keys)** * {Object}* * {Array}* <br />
423
+ Returns a new object that contains all values from the given
424
+ object that have a key which is also in the array keys.
425
+
426
+ ** $.withoutKeys(object, keys)** * {Object}* * {Array}* <br />
427
+ Returns a new object that contains all value from the given
428
+ object that do not have a key which is also in the array keys.
429
+
430
+ ** $.dform.options** <br />
431
+ Static options for generating a form. Currently only $.dform.options.prefix
432
+ is being used.
433
+
434
+ ** $.dform.defaultType(options)** * {Object}* <br />
435
+ A type generator that will be used when no other registered type has been found.
436
+ The standard generator creates an HTML element according to the type given:
437
+
438
+ {
439
+ "type" : "a",
440
+ "href" : "http://daffl.github.com/jquery.dform",
441
+ "html" : "Visit the plugin homepage"
442
+ }
443
+
444
+ Generates:
445
+
446
+ <a class="ui-dform-a" href="http://daffl.github.com/jquery.dform">Visit the plugin homepage</a>
447
+
448
+ ** $.dform.types(\[ name\] )** * {String}* <br />
449
+ Returns all type generators for a given type name. If no name is given, a map of type names
450
+ to an array of generator functions will be returned.
451
+
452
+ ** $.dform.addType(name, generator \[ , condition\] )** * {String}* * {Function}* * {Boolean}* <br />
453
+ Add a new type with a given name and generator function which takes the options as the parameter
454
+ and returns a new element. Optionally pass a condition which will add the type only if
455
+ it returns true.
456
+
457
+ ** $.dform.subscribe(name, subscriber \[ , condition\] )** <br />
458
+ ** $.dform.subscribers** <br />
459
+
460
+ ** $.dform.hasSubscription(name)** * {String}* <br />
461
+ Returns if there is any subscribers with the given name.
462
+
463
+ ** $.dform.createElement(options)** <br />
464
+
413
465
## jQuery UI
414
466
415
467
jQuery.dForm automatically adds support for jQuery UI if it is available. If the form has the * ui-widget* class
@@ -440,17 +492,18 @@ Creates a [slider element](http://jqueryui.com/demos/slider/).
440
492
}
441
493
442
494
** accordion** ` { "type" : "accordion" } ` <br />
443
- Creates a container for a jQuery UI accordion. Use the entries subscriber to add elements.
495
+ Creates a container for a jQuery UI accordion. Use the * entries* subscriber to add elements.
444
496
445
497
** tabs** ` { "type" : "tabs" } ` <br />
446
- Creates a container for a set of jQuery UI tabs. Use the entries subscriber to add elements.
498
+ Creates a container for a set of jQuery UI tabs. Use the * entries* subscriber to add elements.
447
499
448
500
### Subscribers
449
501
450
502
Some other features have been implemented as subscriber, e.g. adding entries to an accordion or making an element
451
503
resizable:
452
504
453
505
** entries** * {Object}* <br />
506
+ Add entries to an * accordion* or * tabs* element.
454
507
455
508
** dialog** * {Object}* <br />
456
509
@@ -481,17 +534,21 @@ to the element:
481
534
}
482
535
}
483
536
537
+ If the form has the * ui-widget* class the jQuery UI CSS error classes will be used to highlight
538
+ invalid fields.
539
+
484
540
### jQuery Globalize
485
541
486
- If [ jQuery.Globalize]
542
+ [ jQuery.Globalize] adds some nice internationalization to JavaScript. If available, the * html* and * options*
543
+ subscriber are enabled to use internationalized strings and option lists.
487
544
488
545
## Changelog
489
546
490
547
__ 0.2.0__
491
548
492
549
* Improved documentation using DocumentUp
493
550
* QUnit test suite runs test for the complete core
494
- * Changed API
551
+ * Major API improvements
495
552
496
553
__ 0.1.4__
497
554
0 commit comments