Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ManyManyDataObjectManager in ModelAdmin breaks save action

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1718 Views
  • geyer
    Avatar
    Community Member
    5 Posts

    ManyManyDataObjectManager in ModelAdmin breaks save action Link to this post

    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().

  • UncleCheese
    Avatar
    4085 Posts

    Re: ManyManyDataObjectManager in ModelAdmin breaks save action Link to this post

    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?

  • geyer
    Avatar
    Community Member
    5 Posts

    Re: ManyManyDataObjectManager in ModelAdmin breaks save action Link to this post

    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

    1718 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.