mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT GridFieldRelationAdd->placeholderText (SSF-53)
This commit is contained in:
parent
3f07b9bffa
commit
04698ac295
@ -27,6 +27,11 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
|
||||
*/
|
||||
protected $resultsFormat = '$Title';
|
||||
|
||||
/**
|
||||
* @var String Text shown on the search field, instructing what to search for.
|
||||
*/
|
||||
protected $placeholderText;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $searchFields Which fields on the object in the list should be searched
|
||||
@ -57,6 +62,7 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
|
||||
$searchField = new TextField('gridfield_relationsearch', _t('GridField.RelationSearch', "Relation search"), $value);
|
||||
// Apparently the data-* needs to be double qouted for the jQuery.meta data plugin
|
||||
$searchField->setAttribute('data-search-url', '\''.Controller::join_links($gridField->Link('search').'\''));
|
||||
$searchField->setAttribute('placeholder', $this->getPlaceholderText($gridField->getList()->dataClass()));
|
||||
$searchField->addExtraClass('relation-search');
|
||||
|
||||
$findAction = new GridField_Action($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find');
|
||||
@ -192,6 +198,41 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
|
||||
return $this->searchFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String The class of the object being searched for
|
||||
* @return String
|
||||
*/
|
||||
public function getPlaceholderText($dataClass) {
|
||||
if($this->placeholderText) {
|
||||
return $this->placeholderText;
|
||||
} else {
|
||||
$labels = array();
|
||||
foreach($this->searchFields as $searchField) {
|
||||
$label = singleton($dataClass)->fieldLabel($searchField);
|
||||
if($label) $labels[] = $label;
|
||||
}
|
||||
if($labels) {
|
||||
return sprintf(
|
||||
_t('GridField.PlaceHolderWithLabels', 'Find %s by %s', PR_MEDIUM, 'Find <object type> by <field names>'),
|
||||
singleton($dataClass)->plural_name(),
|
||||
implode(', ', $labels)
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
_t('GridField.PlaceHolder', 'Find %s', PR_MEDIUM, 'Find <object type>'),
|
||||
singleton($dataClass)->plural_name()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String
|
||||
*/
|
||||
public function setPlaceholderText($text) {
|
||||
$this->placeholderText = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will provide a StartsWith search that only returns a value if we are
|
||||
* matching ONE object only. We wouldn't want to attach used any object to
|
||||
|
Loading…
x
Reference in New Issue
Block a user