Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ModelAdmin form layout


Go to End


3 Posts   2058 Views

Avatar
Sphere

Community Member, 46 Posts

1 February 2011 at 5:07am

I want my form lay-out to be nice and straight.

It's for the opening-hours of my customer, and he wants something like this:
opening closing
Monday [input] [input]
tuesday [input] [input]

You get the point.

Problem is, with just field grouping, the fields aren't aligned straight in one line (quite ugly)

Anyone got a clue on how to render these fields as in a table?

I've tried "hacking" a table in by editing the labels, but that only ends up with just as skewed fields.

Avatar
swaiba

Forum Moderator, 1899 Posts

1 February 2011 at 6:39am

in the ModelAdmin::init....

Requirements::css("mysite/css/modeladminform.css");

mysite/css/modeladminform.css

.MangoFieldGroup {margin-bottom:10px;clear:both;height:55px;}
.MangoFieldGroup .field, .MangoFieldGroup .field label, .MangoFieldGroup .field div{display:block;float:left;clear:none;width:80px;} 

in your dataobject, surrounding the fields to be grouped

$fields->insertBefore(new LiteralField('MangoFieldGroup'.$strStartField,'<div class="MangoFieldGroup">'),$strStartField);
$fields->insertAfter(new LiteralField('MangoFieldGroup'.$strEndField,'</div>'),$strEndField);

not the cleanest of solutions, but it does work :)

Avatar
Sphere

Community Member, 46 Posts

1 February 2011 at 11:31pm

It's cleaner then my "solution" in any way, so :D thnx.