Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW SearchableDropdownField #11057

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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