Skip to content

Commit

Permalink
NEW SearchableDropdownField
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 12, 2023
1 parent cfd8f05 commit f2acbac
Show file tree
Hide file tree
Showing 7 changed files with 866 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
29 changes: 29 additions & 0 deletions src/Forms/SearchableDropdownField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace SilverStripe\Forms;

use SilverStripe\Forms\DropdownField;

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';

/**
* @param string $name
* @param string $title
* @param DataList|ArrayList|ArrayAccess|array $source
* @param mixed $value
* @param string $labelField
*/
public function __construct($name, $title = '', $source = [], $value = null, $labelField = 'Title')
{
// Note that an ancestor constructor will call $this->setSource() which will call
// setSource() in this class which throw an exception if $source is not a DataList
parent::__construct($name, $title, $source, $value);
$this->setLabelField($labelField);
$this->addExtraClass('ss-searchable-dropdown-field');
}
}
Loading

0 comments on commit f2acbac

Please sign in to comment.