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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Ajax search field for has_one relationship in Model Admin


Go to End


955 Views

Avatar
Optic Blaze

Community Member, 190 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
(
'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'
);