A CMS form field for adding has_one relationships using autocomplete

2.11.4 2022-05-10 22:45 UTC

This package is auto-updated.

Last update: 2024-04-11 03:17:54 UTC



This module adds a field for using an autocomplete dropdown to assign a has_one relationship. It's styled after the URLSegment field.

FORK CHANGES: Added support for functions as result list title ( fields are accessible as get{FieldName} functions just with the function name )

Maintainer Contacts


  • SilverStripe 4.0+

For SilverStripe 3.x see the version 1 branch on Github:

Installation Instructions

Via composer:

composer require primoz2500/hasoneautocompletefield

Or manually download the module and place it in a folder called hasoneautocompletefield in your site root.



Example code:


use SilverStripe\CMS\Model\SiteTree;
use NathanCox\HasOneAutocompleteField\Forms\HasOneAutocompleteField;

class Page extends SiteTree
    private static $db = [];

    private static $has_one = [
        'LinkedPage' => 'Page'

    public function getCMSFields()
        $fields = parent::getCMSFields();

        $fields->addFieldToTab('Root.Content', $pageField = HasOneAutocompleteField::create('LinkedPageID', 'Linked Page', 'Page', 'Title'));
        $pageField->setSearchFields(array('Title', 'Content'));

        return $fields;

Known Issues

Issue Tracker