fullscreeninteractive/silverstripe-ajaxuniquetextfield

Text field that checks uniqueness via AJAX and server-side validation for a DataObject field.

Maintainers

Package info

github.com/fullscreeninteractive/silverstripe-ajaxuniquetextfield

Type:silverstripe-vendormodule

pkg:composer/fullscreeninteractive/silverstripe-ajaxuniquetextfield

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-04-12 04:16 UTC

This package is auto-updated.

Last update: 2026-04-12 04:25:39 UTC


README

CI

Provides AjaxUniqueTextField with client and server-side uniqueness validation on a DataObject field, an HTTP JSON endpoint, and a jQuery Entwine client script (load jQuery and Entwine in your project; the CMS admin already includes them).

Requirements

  • SilverStripe CMS 6.x (silverstripe/framework ^6)
  • PHP 8.3 or newer

Installation

Install with Composer from your project root (the same directory as your site’s composer.json):

composer require fullscreeninteractive/silverstripe-ajaxuniquetextfield

Then rebuild the database manifest so configuration and routes are picked up:

vendor/bin/sake dev/build flush=1

Or open /dev/build?flush=1 in the browser while logged in as an administrator.

Exposed module assets are published by the vendor plugin. If JavaScript does not load after an upgrade, run:

composer vendor-expose

Usage

use FullscreenInteractive\AjaxUniqueTextField\AjaxUniqueTextField;

$fields->push(
    AjaxUniqueTextField::create('Slug', 'URL segment', $this->Slug)
        ->setRecordClass(MyRecord::class)
        ->setUniqueField('Slug')
        ->setExcludeID($this->ID) // when editing an existing record
        // ->setValidateURL('https://example.com/custom-check') // optional
        // ->setRestrictedRegex('^[a-z0-9-]+$') // optional client-side gate before AJAX
);

The constructor matches TextField: name, title, value, optional maxLength, optional Form. Configure the DataObject class and field name with setRecordClass() and setUniqueField() before the field is rendered or validated.

Development

  • composer test — PHPUnit (requires MySQL; see vendor/silverstripe/framework/tests/bootstrap/environment.php for defaults).
  • composer phpcs — PSR-12 via PHP_CodeSniffer.
  • composer phpstan — static analysis.