← Back to team overview

anewt-developers team mailing list archive

Re: [Bug 527946] [NEW] Subform support

 

On 16-9-2010 23:58, Wouter Bolsterlee wrote:
Op donderdag 25-02-2010 om 19:03 uur [tijdzone +0000], schreef Sander
van Schouwenburg (Sandworm):
It is not possible to have several forms with just one submit button.
Normally you wouldn't need this, but there are situations where this
would be very useful.

One such situation is this: Suppose you have some element with all
kinds
of annotations, and all those annotations can be in multiple
languages.
And you want to have one form with the element plus all those
annotations in all languages. You could make one form and manually add
controls for all languages and give them unique and meaningful id's,
and
during processing you reconstruct the elements from the id's. But this
is very cumbersome. It would be much better to create one form for
each
language, and have all forms combined into a single form with one
submit
button.

One way is modifying the renderer so that it doesn't render the actual
<form>  element, then render all the forms and manually enclose them
with
a<form>  element. But you still have the problem that the names should
be unique in the whole form node, and the id's should even be unique
in
the whole document.

Fwiw, isn't this what fieldsets + a simple factory function could be
used for?

I don't really see how it could be simple, since you need a hierarchy of controls, and an AnewtForm is flat. Sure you could flatten it, and during processing blow it up again, but that's what I meant with 'cumbersome'.

Ideally what I would want is this:

class TextForm extends AnewtForm {
  function __construct($text) {
    // add controls for title, introduction, text
  }
  function handle_valid() {
    save_something($this->get_control_values());
  }
}

class ProductForm extends AnewtForm {
  function __construct($product) {
    // some basic controls
    foreach ($product->get_texts() as $text) {
      $c = new AnewtFormControlSubForm(new TextForm($text));
      $this->add_control($c);
    }
  }

  function is_valid() {
    return parent::is_valid() && $this->subforms_valid()
  }

  function handle_valid() {
    $this->process_subforms();
  }
}

Possibly those is_valid() and handle_valid() definitions automated.

-- Sander



References