in reply to Re^2: Form generation and validation
in thread Form generation and validation

I don't see anything blocking you from passing in the array (with one element if there is only one) and using a Template loop.

<label for="[% fields.0.id %]">[% fields.0.name %] = </label> <input name="[% fields.0.id %]" placeholder="[% fields.0.placeholder +%]" type="text" id="[% fields.0.id %]" [% fields.0.required %] pattern="[% fie +lds.0.regex %]" > [% FOREACH field IN fields %] [% NEXT IF loop.first %] <label> - </label> <input name="[% field.id %]" placeholder="[% field.placeholder %]" ty +pe="text" id="[% field.id %]" [% field.required %] pattern="[% field.reg +ex %]" > <label for="[% field.id %]">[% field.units %]</label> [% END %]

$fields = [{ id => 'loww1', placeholder => 400, ... }, { ... }];

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^4: Form generation and validation
by Anonymous Monk on Aug 01, 2019 at 11:21 UTC
    I don't see anything blocking you from passing in the array (with one element if there is only one) and using a Template loop.
    Paraphrasing Tolstoy, all template-conforming fields are alike; each non-template-conforming field is different in its own way. One example I had provided involves multiple inputs per field; another might have a bunch of specialised CSS classes or require a small piece of JavaScript attached to it to provide necessary interactivity where available, and so on. If I try to write a template general enough to tend to all of them, it would be a mess, I expect. On the other hand, storing pieces of Template code (i.e. providing specialised mini-templates for non-standard fields) in the form description seems against interface/behaviour separation.