Skip to content

Patch: Update FilteredDropdownSet so that returnLabel can also be a method instead of a field. #50

Description

@hdrlab

I needed to use a FilteredDropdownSet, but the label in the dependent dropdown box came from a method (e.g., getFullName()) instead of a single database field. This required a small modification to the FilteredDropdownSet. I think that this might be useful for others too.

The change is too small for me to bother forking the project and sending a pull request, so here's the patch:


code/dropdown_fields/FilteredDropdownSet.php | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/code/dropdown_fields/FilteredDropdownSet.php b/code/dropdown_fields/FilteredDropdownSet.php
index 09da7dd..64267e6 100755
--- a/code/dropdown_fields/FilteredDropdownSet.php
+++ b/code/dropdown_fields/FilteredDropdownSet.php
@@ -52,7 +52,9 @@ class FilteredDropdownSet extends FieldGroup {
$results = DataObject::get($this->sourceClass, $filter);
if($results) {
foreach($results as $r) {

  •           $ret[$r->{$this->returnKey}] = $r->{$this->returnLabel};
    
  •           $ret[$r->{$this->returnKey}] = 
    
  •               ($r->hasMethod($this->returnLabel) ? 
    
  •                   $r->{$this->returnLabel}(): $r->{$this->returnLabel});
        }  
    }
    return Convert::array2json($ret);
    
    --
    1.7.7.GIT

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions