[html-formfu] handling repeatable on the javascript side

Mario Minati mario.minati at googlemail.com
Sat Apr 25 19:38:36 GMT 2009


Am Samstag 25 April 2009 10:38:47 schrieben Sie:
> Am Mittwoch 22 April 2009 08:50:16 schrieb Carl Franks:
> > 2009/4/21 Mario Minati <mario.minati at googlemail.com>:
> > > Am Dienstag 21 April 2009 14:37:43 schrieb Carl Franks:
> > >> 2009/4/21 Mario Minati <mario.minati at googlemail.com>:
> > >> > Hi,
> > >> >
> > >> > I'm just working on the implementation of client side repeatable
> > >> > elements for ExtJS.
> > >> >
> > >> > What I stumbled about are more complex forms with repeatable
> > >> > repeatables or nested repeatable or repeatable nested or ...
> > >> >
> > >> > Currently I see no automatic way to determine on the client side if
> > >> > a given element name (e.g. inner.outer.name_1) is repeatable nested
> > >> > or nested repeatable, right?
> > >> >
> > >> > The solution the came first to my mind was to analyse the form
> > >> > elements to discover which is repeatable and which is only nested.
> > >> > But that will not work in ExtJS if you choose to display e. g. each
> > >> > repeatable elements in it's own tab (when using a tabpanel). And I
> > >> > didn't want to trade flexibilty automation.
> > >> >
> > >> > So I'm currently thinking of creating a picture of the repeatable
> > >> > and nested structure on the server side and sending this to the
> > >> > client, so the client can easily findout on how to build form and
> > >> > element names.
> > >> >
> > >> > What do you think of this?
> > >> >
> > >> > Can you think of any more elegant solution?
> > >> >
> > >> > And shall we put the code to generate that 'picture' of the form
> > >> > structure into generic formfu, a plugin or just into FF::ExtJS
> > >> > class?
> > >>
> > >> That's certainly a viable solution.
> > >>
> > >> However, I'd prefer it if the Repeatable munging of field names were
> > >> "fixed" so that, for example, a repeatable-repeatable wasn't
> > >>     foo.bar_1_1
> > >> but
> > >>     foo_1.bar_1
> > >>
> > >> I think this would solve your dilemma of needing to differentiate
> > >> between repeatable + nested.
> > >
> > > This would be the most elegant solution and means rewriting the
> > > nested_name handling.
> > >
> > > If you agree with that way, than I'm willing to dive into that task.
> > >
> > > Currently the code that changes the field names lives in Repeatable.pm
> > > in the method repeat.
> > > Actually I think changing that method to add '_$rep' to the nested_name
> > > should do (roughly) the job.
> > >
> > > To do it correctly I would like to comment the repeat method very
> > > intensive. Is that ok when commiting those comments?
> > >
> > > Shall make the behavior configurable to keep backwards compatibility?
> >
> > Yes - feel free to do it!
> > Yes - comments are good :)
> >
> > Backwards compatibility? Unless someone pipes up that they already
> > have client-side code depending on it - don't bother - it'll just make
> > our code more complicated.
>
> Hi Carl,
>
> is a Repeatable without a nested name possible, maybe for radios or
> checkboxes?

Actually I found this problem in 't/elements/block_repeatable_inc.yml'.
The old implementation produced:

<form action="" method="post">
<fieldset>
<div>
<div class="text">
<input name="foo_1" type="text" />
</div>
<div class="text">
<input name="bar_1" type="text" />
</div>
</div>
<div>
<div class="text">
<input name="foo_2" type="text" />
</div>
<div class="text">
<input name="bar_2" type="text" />
</div>
</div>
<div class="submit">
<input name="submit" type="submit" />
</div>
</fieldset>
</form>

The one returns:
<form action="" method="post">
<fieldset>
<div>
<div class="text">
<input name="_1.foo" type="text" />
</div>
<div class="text">
<input name="_1.bar" type="text" />
</div>
</div>
<div>
<div class="text">
<input name="_2.foo" type="text" />
</div>
<div class="text">
<input name="_2.bar" type="text" />
</div>
</div>
<div class="submit">
<input name="submit" type="submit" />
</div>
</fieldset>
</form>

To resolve this problem I can think of some solutions:
a) Croak without a nested_name for Repeatable
b) Use old implementation (nested.foo_1) if no nested_name is given
c) Autocreate a nested_name if non is given

What do you think?


Greets,

Mario



More information about the HTML-FormFu mailing list