5450 Posts in 1672 Topics by 1197 members
Page: 1 2
|Go to End||Next >|
7 January 2011 at 8:14am
I have been working with ModelAdmin and I'm having trouble getting the fields to display the way I want. When I click the create record button the fields are displayed on the tabs I have created, but some of them I want to be inside a fieldgroup.
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Main", new TextField('Name', 'Name'));
$fields->addFieldToTab("Root.Main", new TextField('Country', 'Country'));
$fields->addFieldToTab("Root.Main", new TextField('Continent', 'Continent'));
$fields->addFieldToTab("Root.Main", new FieldGroup(
new TextField('FirstYear', 'First Year'),
new TextField('LastYear', 'LastYear')
I get this error with this code.
Error: "collateDataFields() I noticed that a field called 'FirstYear' appears twice in your form: 'Form_AddForm'. One is a 'TextField' and the other is a 'TextField'" at line 140 of ....../sapphire/forms/CompositeField.php
Is this not supported in ModelAdmin, or am I missing something?
7 January 2011 at 1:25pm
Seems like you are adding the field again... Remember by default ModelAdmin creates your form with all the fields from the mangaed_model... try adding this after the parent:: call...
... to remove the field ModelAdmin has probably created for you
7 January 2011 at 3:09pm
Thanks for the reply.
That took the error away but it did not move those two fields to be beside each other. This isn't a huge issue, purely aesthetics. I have 50 or more fields in this model and I'm just trying to minimize scrolling.
7 January 2011 at 10:34pm
Couple of hints...
1) The order of the fields specified int he DataObject are the order they are displayed in ModelAdmin form.
2) you can replace a fields with...
(stead of add field to tab)
3) You could remove the field from teh main tab, then add the field to another tab...
$tab = $fields->findOrMakeTab('Root.NewTab');
4) You can create your own pieces of HTML throughout the form by inserting before/after your own code...
...you could insertAfter or insertBefore, you could start, then stop a table or as above I've entered a HR tag...
p.s. I've never used FieldGroup so I cannot advise on it
1 March 2011 at 6:15am
Would you mind explaining this a little further.
I searched through the whole forum about creating a nicer layout for the modeladmin form. All i find are "bits-and-pieces".
I need to reorganize the modeladmin form to get a 'cleaner' presentation. Meaning; more fields in a row and put each field in the next row directly above/below the other fields.
I read a lot about insertafter insertbefore etc. but i just can't get any 'grip'on it.
I've used fieldgroups now... it works but it's not getting any nicer.
I attached a file to explain.
1 March 2011 at 10:37pm
didn't I already send you this link?
I encourage someone to post the correct usage of FieldGroup or more accurately answer this question - all I ever needed was a couple of fields in line.
3 March 2011 at 9:10am
I'm sorry...Yes you did send me that link in an other post. One question remains...how and where do i specify the strings $strStartField and $strEndField?
Would it be like $strEndField = array() ?
3 March 2011 at 9:29am
Maybe I should have written...
<StartField> and <EndField>
they are to be replaced by fields from your $db array
Page: 1 2
|Go to Top||Next >|