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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

ModelAdmin issues


Go to End
Reply


5 Posts   1688 Views

Avatar
mi3ll

Community Member, 24 Posts

18 February 2009 at 1:45pm

Edited: 19/02/2009 2:05am

Has anyone got the ModelAdmin code working in RC4? If so, I would be grateful if you can share your code or share what I am doing wrong, thanks.

I've been having problems extending ModelAdmin in the RC4 and RC3 versions. It displays all right, but when I click the Create and Search buttons the ajax loading image fills the right hand screen and nothing happens (ajax error...)

I checked the Error console in Firefox and it gives me this error:

Too much recursion
$('Form_CreateForm').validate is not a function

I noticed that ModelAdmin loads both jquery and prototype, and the validation use $ function which they both use, so I'm thinking there must be a conflict? I'm not very good with javascript.

Great application by the way!

EDIT: If it helps, here is my other code:

Stockist Dataobject

<?php
/**
 * Data representing a stockist
 */
class Stockist extends DataObject {
 
   static $db = array(
      'Name' => 'Varchar',
      'Contact' => 'Varchar',
      'Address' => 'Text',
	  'City' => 'Varchar',
	  'Postcode' => 'Varchar',
	  'Phone' => 'Varchar',
	  'Fax' => 'Varchar',
	  'Mobile' => 'Varchar',
	  'Email' => 'Varchar',
	  'Website' => 'Varchar',
	  'FullStockist' => 'Boolean',
	  'Date' => 'Date',
   );
 
   static $has_one = array(
      'Location' => 'Location'
   );
 
   static $searchable_fields = array(
      'Name' => array(
          'field' => 'TextField',
          'filter' => 'PartialMatchFilter',
       ),
      'Contact' => array(
          'field' => 'TextField',
          'filter' => 'PartialMatchFilter',
       ),
	  'Address' => array(
          'field' => 'TextareaField',
          'filter' => 'PartialMatchFilter',
       ),
	  'City' => array(
          'field' => 'TextField',
          'filter' => 'PartialMatchFilter',
       ),
	  'Location.Name' => array(
		  'title' => 'Location',
          'field' => 'TextField',
          'filter' => 'PartialMatchFilter',
       ),
	  'Postcode' => array(
          'field' => 'NumericField',
		  'filter' => 'ExactMatchFilter',
       ),
	  'FullStockist' => array(
		  'title' => 'Is a full stockist?',
          'field' => 'CheckboxField',
		  'filter' => 'ExactMatchFilter',
       ),
	  'Location.InAustralia' => array(
		  'title' => 'Only in Australia?',
          'field' => 'CheckboxField',
		  'filter' => 'ExactMatchFilter',
       )
   );
   
   static $summary_fields = array(
      'Name',
	  'City',
      'Location.Name' => 'Location',
	  'Phone',
	  'FullStockist'
   );

    function getCMSFields() {
                // test
		$fields = new FieldSet();
		$fields->push(new TextField('Name', 'Business Name'));
		return $fields;
    }  
}

?>

StockistAdmin.php

<?php
/**
 * Interface for maintaining stockists
 */
class StockistAdmin extends ModelAdmin {
   
  protected static $managed_models = array(
      'Stockist',
      'Location'
   );
 
  static $url_segment = 'stockists';
  static $menu_title = 'Stockists';
 
}

?>

Inside my config file

Director::addRules(50, array('admin/stockists/$Class/$Action/$ID' => 'StockistAdmin'));

Avatar
Ben Gribaudo

Community Member, 181 Posts

19 February 2009 at 3:14am

Hi mi3ll,

Have you tried getting things working while using trunk? With the references to "Location" commented out (since I didn't have that model), the create button seemed to work fine on my system when I used a trunk checkout from yesterday.

Also, I think the Director::addRules line is unnecessary with the current version of ModelAdmin.

Hope this helps a little,
Ben

Avatar
mi3ll

Community Member, 24 Posts

19 February 2009 at 2:14pm

Edited: 19/02/2009 2:17pm

Hi bgribaudo,

Thanks for replying! Yes, using the daily build from 17-02-2009 worked! Of course the answer was so simple...

Thanks for telling me about that line, I tried using ModelAdmin in RC4 and it would not work without that line for me (I mean, adding this line produced more closely the results I wanted, but didn't really work xD)

Avatar
Fuzz10

Community Member, 787 Posts

24 February 2009 at 8:30am

I seem to be having the same problem in the final release 2.3.0.

Would you mind trying your code in the final release ?

Avatar
Fuzz10

Community Member, 787 Posts

24 February 2009 at 11:09pm

Ah.. my problem was solved by removing HTMLFields in the dataobject. ModelAdmin doesn't like those. ;)