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.

Data Model Questions /

Ajax search field for has_one relationship in Model Admin



Optic Blaze

Community Member, 165 Posts

3 October 2012 at 11:15am

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
   static $has_one = array(
   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);

    return $fields;

   // Sets the sumary fields that will be displayed in teh grid field
   static $summary_fields = array(