Skip to content

Commit

Permalink
NEW SearchableDropdownField
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 14, 2023
1 parent ff38ff1 commit 23eca53
Show file tree
Hide file tree
Showing 7 changed files with 873 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ en:
IsNullLabel: 'Is Null'
SilverStripe\Forms\NumericField:
VALIDATION: "'{value}' is not a number, only numbers can be accepted for this field"
SilverStripe\Forms\SearchableDropdownTrait:
SELECT: 'Select...'
TYPE_TO_SEARCH: 'Type to search...'
SELECT_OR_TYPE_TO_SEARCH: 'Select or type to search...'
SilverStripe\Forms\TextField:
VALIDATEMAXLENGTH: 'The value for {name} must not exceed {maxLength} characters in length'
SilverStripe\Forms\TimeField:
Expand Down
40 changes: 40 additions & 0 deletions src/Forms/SearchableDropdownField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace SilverStripe\Forms;

use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\DropdownField;
use SilverStripe\ORM\DataList;

class SearchableDropdownField extends DropdownField
{
use SearchableDropdownTrait;

// This needs to be defined on the class, not the trait, otherwise there is a PHP error
protected $schemaComponent = 'SearchableDropdownField';

public function __construct(
string $name,
string $title,
DataList $source,
mixed $value = null,
string $labelField = 'Title'
) {
parent::__construct($name, $title, $source, $value);
$this->setLabelField($labelField);
$this->addExtraClass('ss-searchable-dropdown-field');
$this->setHasEmptyDefault(true);
}

/**
* @param string $string
* @return $this
*
* @deprecated 5.2.0 Use setPlaceholder() instead
*/
public function setEmptyString($string)
{
Deprecation::notice('5.2.0', 'Use setPlaceholder() instead');
return parent::setEmptyString($string);
}
}
Loading

0 comments on commit 23eca53

Please sign in to comment.