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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ManyManyDataObjectManager in ModelAdmin breaks save action


Go to End


3 Posts   2878 Views

Avatar
geyer

Community Member, 5 Posts

11 May 2009 at 9:59pm

Has anyone gotten the ManyManyDataObjectManager to work properly in ModelAdmin?

Currently, when I replace the default many-many relationship field with the ManyManyDataObjectManager, it stops me from being able to save changes on other fields/tabs.

i.e. if I make a change to any other field, I can't save the change(s) until I make a change on the MMDOM.

I'm using SS version 2.3.1 and DataObjectManager r137.

Some sample code:

class Company extends DataObject  {

	static $db = array(
		'Name' => 'Varchar(200)'
	);

	static $many_many = array(
		'BusinessTypes' => 'BusinessType'
	);

	function getCMSFields() {
		
		$fields = parent::getCMSFields();
		
		$fields->removeFieldFromTab( 'Root.BusinessTypes', 'BusinessTypes' );
		
		$fields->addFieldToTab( 'Root.BusinessTypes', new ManyManyDataObjectManager(
			$this,
			'BusinessTypes',
			'BusinessType',
			array( 'Name' => 'Business Type' )
		));		
		
		return $fields;
	}
}

update

To make it a bit more confusing - saving seems to work fine is you strip out the default TabSet.
You can do this by calling

$fields->changeFieldOrder( array( 'Name', 'BusinessTypes' ) )
inside getCMSFields().

Avatar
UncleCheese

Forum Moderator, 4102 Posts

12 May 2009 at 2:34am

I know next to nothing about ModelAdmin, but I'm very interested in the concept. I'd be interested in any input you guys have on getting DOM ModelAdmin compliant.

This sounds like a javascript error. Is DOM fighting with the Tabset, perhaps? Can you check Firebug?

Avatar
geyer

Community Member, 5 Posts

12 May 2009 at 9:13pm

Hi UncleCheese,

Firebug saved the day!

It was complaining that some function in jqeury (ui.core line 136) was failing. Tracked it back to a calls made in /cms/javascript/ModelAdmin.js line ~24. Just put the calls in a try-catch and everything seems to be working again.

So in other words, my /cms/javascript/ModelAdmin.js now looks like this:

// Line ~21

/**
 * Attach tabs plugin to the set of search filter and edit forms
 */

$('ul.tabstrip').livequery(function() {	
	try
	{
		$(this).tabs();
		
		$(this).tabs({ 
			// This show handler is necessary to get tabs working properly with the crappy old layout_helpers.js layout 
			// manager 
			show : function() { 
				if(window.onresize) window.onresize(); 
			} 
		});
	}
	catch(err)
	{
		// do nothing?
	}		
});

Hope that helps somebody :)