Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Ajax search field for has_one relationship in Model Admin

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

Page: 1
Go to End
Author Topic: 441 Views
  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Ajax search field for has_one relationship in Model Admin Link to this post

    Hi there,

    I have two classes.

    1) Postal Codes
    2) Insurer

    There exists a has_one relationship between the Insurer and Postal Codes and i only need back end functionality eg i only need to add/edit records via model admin.

    The problem that i am sitting with is that there are 10 000 postal codes to choose from. Loading 10 000 records into a dropdown field does not work. I have set the system up in model admin and it works. I just need help figuring out how to do a ajax type search on the postal codes field. See existing code below:

    class Insurer extends DataObject
    {
       static $db = array
       (
           'Name'=>'Varchar(100)',
          'DateJoined'=>'Date',
          'Tel'=>'Varchar(10)',
          'Fax'=>'Varchar(10)',
          'VatNo'=>'Varchar(10)',
          'PostalAddress'=>'Text',
          'IsActive'=>'Boolean(1)'
       );
       
       static $has_one = array(
       'PostalCode'=>'PostalCodes',
       );
       
       function getCMSFields() {
          $fields = new FieldList(
          new TextField('Name','Company Name'),               
          $dateField = new DateField('DateJoined', 'DateJoined',date("Y-m-d")),
          new TextField('Tel','Telephone Number'),
          new TextField('Fax','Fax Number'),
          new TextField('VatNo','Vat Number'),
          new TextareaField('PostalAddress','Postal Address'),
          new CheckboxField('IsActive', 'Is this insurer active?',1),
          new DropdownField('PostalCode', 'Postal Code', PostalCode::get()->map('ID', 'Suburb')) /// How do i make this a ajax search
           );
        $dateField->setConfig('showcalendar', true);
        $dateField->setConfig('dateformat','yyyy-MM-dd');
        $dateField->setConfig('min','2012-01-01');

        return $fields;
       }

       
       // Sets the sumary fields that will be displayed in teh grid field
       static $summary_fields = array(
    'Name',
        'DateJoined',
    'Tel',
        'Fax'
    );
       
       

    441 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.