Easy way to group Form fields that are created by setModel?


#1

Hi There,

the following form is created by passing a model to a Form using Form->setModel():
group_formfields_from_model

Now, I would like to have Start Date and Start Time in one row. If the form fields were not created by setModel(), I would simply use Form->addGroup() to achieve what I want.

The only solution I can think of is to only load the fields which are displayed before, then add a the groups, then add the fields that come after, something like this, not too nice:

$tour = $tour_form->setModel(new Pmg\Tour($app->db), ['name', 'tour_type_id', 'meeting_point_id']);
$start = $tour_form->addGroup('Start');
$start->addField('start_date');
$start->addField('start_time');
$end = $tour_form->addGroup('Start');
$end->addField('end_date');
$end->addField('end_time');
$tour_form->addField('max_guests');

Is there a better way to achieve what I want? Actually I can well think of having a template for each form which defines exactly where which Field is displayed, but that would mean quite a rewrite of FormLayout\Generic->recursiveRender() as far as I understand now.

Best regards
Philipp


#2

Easiest would be to specify 2nd argument to set model with ['name', 'tour_type_id', 'meeting_point_id'].

Then add a field group into the form and add start date/time in there. Then add another group adding ending date/time.

See http://ui.agiletoolkit.org/demos/form.php - Layout section.


#3

Hi,

ok so this is the solution I posted. But it causes a bit of trouble:

$tour = $tour_form->setModel(new Pmg\Tour($app->db), ['name', 'tour_type_id', 'meeting_point_id']);
$start_fields = $tour_form->addGroup(['Start', 'inline' => true]);
$start_fields->addField('start_date');
$start_fields->addField('start_time');
$end_fields = $tour_form->addGroup(['Ende', 'inline' => true]);
$end_fields->addField('end_date');
$end_fields->addField('end_time');
$tour_form->addField('max_guests');


$tour_form->fields['tour_type_id']->on('change', $tour_form->js()->form('submit'));

$tour_form->fields['start_date']->on('focusout', $tour_form->jsInput('end_date')->val($tour_form->jsInput('start_date')->val()));

creates the following error:

Will investigateā€¦
Best regards
Philipp


#4

looks like error is in different place, line 238. Keep reference to the field, then use them.


#5

Hi,

line 238 is the one I posted:
$tour_form->fields['start_date']->on('focusout', $tour_form->jsInput('end_date')->val($tour_form->jsInput('start_date')->val()));

So when the field is in a group, jsInput does not find it any moreā€¦