I currently have a fieldset for my 'list' ORM object. Within this I have added another fieldset to add 'listitems' to the list. These fieldsets are being created and populated within a set_form_fields function in the 'list' model file. This code shows how I build the inner 'listitems' fieldset within the function:
foreach($instance->items as $item) {
$form->add(\Fieldset::forge('item_'.$item->id,
array(
'form_attributes' => array(
'class' => 'itemform'
)
)
)->add_model($item, $item)->populate($item));
}
I am planning on adding a button which uses ajax to dynamically add another listitem field onto the form so that as many can be added and saved as necessary.
The issue I have is that when the code above creates and populates the inner 'listitem' fieldset all of the fields will have the same name and id attributes. I know these are taken from the $_properties array in the model but is there some way I can edit them in the code I have shown above on the fly?
If you want to build a 1:N form, you might want to look at tabular forms, which supports exactly this, and creates the fieldnames as an array so you can add additional rows.
That should not be there. The tabular form feature comes from a Fieldset core extension we have been using in our applications, and the part that adds field icons hasn't made it into the fieldset code (because it's application specific).
So it's safe to remove, and I'll remove it from the 1.6 template.
It generates standard table rows, with array's for fieldnames, so it's very easy to copy the last time using a bit of javascript.
Sometimes we do it this way, sometimes we use an automatic mechanism (if the one before last is filled in, a new empty one will automatically be added at the bottom), and sometimes we just create a form with 10 empty lines.