Helper functions for forms
GvaScript.Form - Helper functions for forms
This component helps to manage HTML forms with hierarchical fields and dynamically repeated sections. [explain]
GvaScript.Form.init(form, initial_tree)
form
is the id of a form (or directly the DOM element). Optional initial_tree
is
a javascript nested datastructure containing initial values for fields.
If the initial tree contains repeated data sets, then the corresponding repeated sections in the form are dynamically expanded (see /fill_from_tree).
[explain more]
var flat_hash = GvaScript.Form.to_hash(form);
Inspects the contents of all fields in form and returns a flat hash of pairs (key-value).
var tree = GvaScript.Form.to_tree(form);
Inspects the contents of all fields in form and returns a data tree, were dotted names in form names are expanded into sub-arrays or sub-hashes.
GvaScript.Form.fill_from_tree(form, field_prefix, tree);
Fills the form from values found in tree
.
Optional field_prefix
is prepended to key names in tree
for
finding the corresponding form fields.
If the initial tree contains repeated data sets, then the corresponding
repeated sections in the form are dynamically expanded.
[explain more]
var tree = GvaScript.Form.expand_hash(flat_hash);
Transforms a flat structure of key-value pairs into a nested tree structure, by splitting keys on dots. The idea and algorithm come from CGI::Expand/expand_hash.