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: Unable to scroll


Go to End


6 Posts   1299 Views

Avatar
merrick_sd

Community Member, 99 Posts

13 January 2012 at 1:23am

has anyone come accross this.

I have used model Admin to display and edit a DataObject but I cannot scroll.

Im using Firefox

code
GlobalAdmin.php
--------------------------------------
class GlobalAdmin extends ModelAdmin {

public static $managed_models = array(
'FooterIcon', 'GlobalBanner', 'FootNote', 'ccswlogin','Office'//'NavStyle'
);

static $url_segment = 'Global'; // will be linked as /admin/products
static $menu_title = 'Global';

}
---------------------------------------

Office.php
<?php

class Office extends DataObject {

static $db = array(
'MainOffice' => 'Boolean',
'CompanyReg' => 'Text',
'VATNo' => 'Text',
'Title' => 'Text',
'Address1' => 'Text',
'Address2' => 'Text',
'Address3' => 'Text',
'Address4' => 'Text',
'City' => 'Text',
'Country' => 'Text',
'Postcode' => 'Text',
'Tel' => 'Varchar',
'Fax' => 'Varchar',
'Email' => 'Varchar',
'OfficeExtra' => 'HTMLText'
);

static $singular_name = 'Office';
static $plural_name = 'Offices';

static $has_one = array(
'SiteTree' => 'SiteTree',
'officepagelink' => 'SiteTree',

);

// Model Admin utilities
static $searchable_fields = array(
'Title',
'Postcode'
//'ID',
//'helpline'
);

static $summary_fields = array(
'MainOffice',
'Title',
'Address1',
'City',
'Postcode',
);

function getCMSFields(){
$source = DataObject::get("SiteTree");
$optionArray = $source->toDropDownMap($index = 'ID', $titleField = 'Title', "--- select page ---", $sort = "Sort");
if($source) foreach( $source as $page ) {
$optionArray[$page->ID] = $page->MenuTitle;
}

$fields = new FieldSet(
//new DropdownField("AllSameASID","Set Links Same As",$optionArray),
new CheckBoxField('MainOffice', "Tick to mark as MainOffice"),
new TextField('CompanyReg', 'Companys House Reg eg: Registered in England 00000','Email'),
new TextField('VATNo', 'VAT No eg:GB 383 8602 20
', 'Email'),
new TextField('Title', 'Office Name'),
new TextField('Address1', 'Address line1'),
new TextField('Address2', 'Address line2'),
new TextField('Address3', 'Address line3'),
new TextField('Address4', 'Address line4'),
new TextField('City', 'City'),
new TextField('Country', 'Country'),
new TextField('Postcode', 'Postcode'),
new TextField('Tel', 'Tel'),
new TextField('Fax', 'Fax'),
new EmailField('Email', 'Email'),

new HtmlEditorField('OfficeExtra', 'ExtraContent'),
new DropdownField("officepagelinkID","Link To Page",$optionArray),

new LiteralField (
$name = "literalfield",$content = "<p>Remember to click Save / Add</p>"
)

);

return $fields;
}

function VarOfficeLink() {

$dos = new DataObjectSet();

$fieldname = "officepagelinkID";
if($this->$fieldname > 0) {
if($page = DataObject::get_by_id("SiteTree", $this->$fieldname - 0)) {
$dos->push($page);
}
}

return $dos;
}

}

?>

This works in the Admin, but I can't scroll down to edit other fields.

Any advice appreciated

picture attached

Attached Files
Avatar
swaiba

Forum Moderator, 1899 Posts

13 January 2012 at 4:32am

Hi,

You are treating model admin like a page, this is wasting your time. ModelAdmin scafolds the fields so you don't have to - all you need to is remove what you don't want (removebyname), change what needs changing (replacefield) and add new things (insertbefore,insertafter).

It is likely sorting the above will sort your problem.

Avatar
merrick_sd

Community Member, 99 Posts

13 January 2012 at 6:08am

When you say Im treating it as a Page.. do you mean i don't need. function getCMSFields()

I haven't extended Page .. I have extended DataObject and ModelAdmin

class Office extends DataObject {

and

class GlobalAdmin extends ModelAdmin {

I did try

function getCMSFields(){

$fields = parent::getCMSFields();
return $fields;
}

Doesn't solve as yes the fields are still rendered but still have same problem in cannot scroll, also fields aren't singular they have drag handles now.

Avatar
swaiba

Forum Moderator, 1899 Posts

13 January 2012 at 6:13am

well - yes you don't need to define getCMSfields - that is the great thing about modeladmin

now if you do want to checnge/add things use the functions above

so if you take the getCMSFields away and it still fails then you problem is not in the dataobject fields, or getCMSFields then is it? so I would say it is not possible to advise becasue *something else* is causing the issue...

Avatar
merrick_sd

Community Member, 99 Posts

19 January 2012 at 12:20am

haha

I found if I don't use a HTMLEditorField i always get scrollbars.

$fields->addFieldToTab('Root.Main',new HtmlEditorField('OfficeExtra'));

so need to figure out how i can have a html tnymce field within model admin or just avoid them i guess

Avatar
swaiba

Forum Moderator, 1899 Posts

19 January 2012 at 12:25am

This is very strange as I use TinyMCE in ModelAdmin all the time with no issue - have you done any hacking or is this a clean install?