Alien-GvaScript

 view release on metacpan or  search on metacpan

lib/Alien/GvaScript/Form.pod  view on Meta::CPAN

  </div>

and if that form has been expanded with 3 repetition blocks
for children, the resulting tree would be

  { "father" : {"firstname" : ..., "lastname": ...},
    "mother" : {"firstname" : ..., "lastname": ...},
    "child"  : [ {"firstname": ...},
                 {"firstname": ...},
                 {"firstname": ...} ] }

[I<This method can be called either as an instance method or as a generic method. If calling as a generic, pass the form HTMLElement/id in as the first argument.>]

=head2 fill_from_tree

  GvaScript.Form.fill_from_tree(form, field_prefix, tree);

Fills the form from values found in C<tree> (this is the 
reverse of the L</to_tree> operation).
Optional C<field_prefix> is prepended to key names in C<tree> for
finding the corresponding form fields.

The method walks through nested subtrees in C<tree>: the sequence
of keys leading to a leaf is concatenated into a flat string, with dot 
separators, and if the form has a corresponding input element,
the value of that element is set to the value of the leaf.
Furthermore, if the initial tree contains repeated data sets
(array subtrees), and if the form contains repeat elements
with the same path, then new repetition blocks are 
dynamically created to match the number of items in the array:
so if the form above is filled with the following tree

  { "child"  : [ {"firstname": "Abel"},
                 {"firstname": "Bob"},
                 {"firstname": "Cod"},
                 {"firstname": "Dave"}, ] }

then four repetition blocks will automatically created in the form.

[I<This method can be called either as an instance method or as a generic method. If calling as a generic, pass the form HTMLElement/id in as the first argument.>]

=head2 add

  GvaScript.Form.add(repeat_name, count);

Creates one or several new repetition blocks.  The parameter C<count>
is optional and defaults to 1.  Focus is automatically given to the
first input element in the last repetition block that has an
C<autofocus> attribute (if any).

See L<Alien::GvaScript::Repeat/add> for more explanations on
the C<add> operation.

=head2 remove

  GvaScript.Form.remove(repeat_block[, live_update]);

Removes a repetition block from the DOM. The argument is either
a DOM element or a string containing the element id.

param C<Boolean> live_update: flag to indicate whether the 'remaining'
repeatable sections are to be also removed from DOM, recreated by re-merging
the data with repeat template, then finally re-appended to the DOM.
Default true.

All repetition blocks above the removed block are renumbered,
leaving no hole in the index sequence. To do so, these
blocks are also removed from the DOM, and then added
again through the L</add> method. This operation is implemented
by L<Alien::GvaScript::Repeat/remove>.

The recreated blocks are then re-populated with their
previous input values.

=head2 autofocus

  GvaScript.Form.autofocus(element);

Inspects DOM children of  C<element>, and gives focus to the 
first child that has an C<autofocus> attribute.

=head1 GvaScript.Forms 

namespace that holds all active instances of GvaScript.Form 

instances are unique per form id

=head2 METHODS 

=head3 get

  GvaScript.Forms.get(id)

finds and returns the GvaScript.Form instance where id is the unique id of the form HTMLElement. 

=head1 GvaScript.Form.Responders

A repository of global listeners notified about every step of the GvaSript.Form lifecycle.

Sometimes, you need to provide generic behaviors over all GvaScript.Form(s) in a single application.

To achieve this, GvaScript.Form provides global Responders that will be executed for every GvaScript.Form instance.

Responders by default are executed B<after> the instance specific event callback.


=head2 METHODS

=head3 register

  GvaScript.Form.Responders.register({eventName: handler}[, {eventName: handler}[, ...]]})

adding one or more global form events responders.

Supported B<eventNames>: C<onInit, onChange, onBeforeSubmit, onSubmit, on[XXX]> where C<on[XXX]> is a custom event name.

=head3 unregister

  GvaScript.Form.Responders.unregister({eventName: handler}[, {eventName: handler}[, ...]]})

unregistering one or more global form events responders.



( run in 0.582 second using v1.01-cache-2.11-cpan-119454b85a5 )