Alien-GvaScript

 view release on metacpan or  search on metacpan

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

    <td><input name="#{bar.path}.buz"></td>
  </tr>

Within the 3rd repetition block of C<bar>, nested
within the 2nd repetition block of C<foo>, the value of
C<#{bar.path}> will be C<foo.2.bar.3> and therefore
in this example the input name would be
C<foo.2.bar.3.buz>.


I<Implementation note>: the C<< #{...} >> syntax for
variables is borrowed from C<prototype.js>'s C<Template>
class; however, the implementation of substitutions
is done in plain javascript, without calling
C<Template.evaluate()> method.

=head1 METHODS

=head2 init

  GvaScript.Repeat.init(element)

Walks down the DOM under the given element, finds all 
elements having a C<repeat> attribute, replaces these
by placeholders.

The C<element> argument will be fed to C<prototype.js>'s
C<$()> function, so it can be either a DOM element or
an id string.

=head2 add

  GvaScript.Repeat.add(repeat_name, count)

Creates one or several new repetition blocks in the DOM, 
after the current blocks, by instanciating
the repeat element C<repeat_name> (including prefix).
The  C<count> argument is optional and states how many blocks
should be added; default is 1. Returns the final number of 
repetition blocks for that repeat element.

If the repeat structure looks like

  <div repeat="foo" repeat-prefix="top">
     <div repeat="bar">

then a new C<foo> repetition block is instanciated
through C<add('top.foo')>, and a new C<bar> repetition
block is instanciated through C<add('#{foo.path}.bar')>.




=head2 remove

  GvaScript.Repeat.remove(repetition_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 below 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.

If the repetition block is within a form, you probably
want to call L<Alien::GvaScript::Form/remove> instead
of the present method, in order to properly preserve
current form data.

=head1 EVENTS

For a general explanation on registering handlers
for GvaScript events, see the L<event> documentation.

=head2 onAdd

  <div repeat="Foo" 
       onAdd="alert('a new Foo is born with index #{Foo.ix}')">

This event is triggered whenever a new repetition block
is created through the L</add> method
(including when the L</init> method
instantiates C<repeat-start> initial repetition blocks).

=head2 onRemove

  <div repeat="Foo" 
       onRemove="alert(event.target.id + ' is removed')">

This event is triggered whenever a repetition block
is removed through the L</remove> method.
Since this method also removes all repetition blocks
above the requested block, the event will be triggered
once for each block.

=head1 SEE ALSO

L<Alien::GvaScript>



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