Alien-GvaScript

 view release on metacpan or  search on metacpan

doc/html/Repeat.html  view on Meta::CPAN

within the 2nd repetition block of <code>foo</code>, the value of
<code>#{bar.path}</code> will be <code>foo.2.bar.3</code> and therefore
in this example the input name would be
<code>foo.2.bar.3.buz</code>.</p>
<p><i>Implementation note</i>: the <code>#{...}</code> syntax for
variables is borrowed from <code>prototype.js</code>'s <code>Template</code>
class; however, the implementation of substitutions
is done in plain javascript, without calling
<code>Template.evaluate()</code> method.</p>

    </div>
  </div>

    </div>
  </div>
  <div class="TN_node" id="METHODS">
    <h2 class="TN_label">METHODS</h2>
    <div class="TN_content">
        <div class="TN_node" id="init">
    <h3 class="TN_label">init</h3>
    <div class="TN_content">
      <pre>  GvaScript.Repeat.init(element)</pre>

<p>Walks down the DOM under the given element, finds all 
elements having a <code>repeat</code> attribute, replaces these
by placeholders.</p>
<p>The <code>element</code> argument will be fed to <code>prototype.js</code>'s
<code>$()</code> function, so it can be either a DOM element or
an id string.</p>

    </div>
  </div>
  <div class="TN_node" id="add">
    <h3 class="TN_label">add</h3>
    <div class="TN_content">
      <pre>  GvaScript.Repeat.add(repeat_name, count)</pre>

<p>Creates one or several new repetition blocks in the DOM, 
after the current blocks, by instanciating
the repeat element <code>repeat_name</code> (including prefix).
The  <code>count</code> 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.</p>
<p>If the repeat structure looks like</p>
<pre>  &lt;div repeat="foo" repeat-prefix="top"&gt;
     &lt;div repeat="bar"&gt;</pre>

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

    </div>
  </div>
  <div class="TN_node" id="remove">
    <h3 class="TN_label">remove</h3>
    <div class="TN_content">
      <pre>  GvaScript.Repeat.remove(repetition_block[, live_update])</pre>

<p>Removes a repetition block from the DOM. The argument is either
a DOM element or a string containing the element id.</p>
<p>param <code>Boolean</code> 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.</p>
<p>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 <a href="#add">/add</a> method.</p>
<p>If the repetition block is within a form, you probably
want to call <i>Alien::GvaScript::Form/remove</i> instead
of the present method, in order to properly preserve
current form data.</p>

    </div>
  </div>

    </div>
  </div>
  <div class="TN_node" id="EVENTS">
    <h2 class="TN_label">EVENTS</h2>
    <div class="TN_content">
      <p>For a general explanation on registering handlers
for GvaScript events, see the <i>event</i> documentation.</p>
  <div class="TN_node" id="onAdd">
    <h3 class="TN_label">onAdd</h3>
    <div class="TN_content">
      <pre>  &lt;div repeat="Foo" 
       onAdd="alert('a new Foo is born with index #{Foo.ix}')"&gt;</pre>

<p>This event is triggered whenever a new repetition block
is created through the <a href="#add">/add</a> method
(including when the <a href="#init">/init</a> method
instantiates <code>repeat-start</code> initial repetition blocks).</p>

    </div>
  </div>
  <div class="TN_node" id="onRemove">
    <h3 class="TN_label">onRemove</h3>
    <div class="TN_content">
      <pre>  &lt;div repeat="Foo" 
       onRemove="alert(event.target.id + ' is removed')"&gt;</pre>

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

    </div>
  </div>

    </div>
  </div>
  <div class="TN_node" id="SEE_ALSO">
    <h2 class="TN_label">SEE ALSO</h2>
    <div class="TN_content">
      <p><i>Alien::GvaScript</i></p>

    </div>
  </div>



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