Skip to content

Commit

Permalink
Issue #2648: Introduce multiselect config param for dynamic field ref…
Browse files Browse the repository at this point in the history
…erence.

Fix handling of PossibleNone to prevent duplicated empty selection option.
  • Loading branch information
stefanhaerter authored and svenoe committed Nov 9, 2023
1 parent 5d72648 commit 7b861f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 23 additions & 0 deletions Kernel/Modules/AdminDynamicFieldReference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ sub _AddAction {
$FieldConfig{$Name} = $GetParam{$Name};
}

# interdependencies of multiselect, multivalue and editfieldmode
# set multiselect key for consistency in backend
$FieldConfig{Multiselect} = $FieldConfig{EditFieldMode} eq 'Multiselect' ? 1 : 0;

# differentiate only between autocomplete and dropdown
$FieldConfig{EditFieldMode} = $FieldConfig{EditFieldMode} eq 'AutoComplete' ? 'AutoComplete' : 'Dropdown';

# multiselect excludes multivalue
$FieldConfig{MultiValue} = $FieldConfig{Multiselect} ? 0 : $FieldConfig{MultiValue};

$GetParam{ReferenceFilterCounter} = $ParamObject->GetParam( Param => 'ReferenceFilterCounter' ) || 0;

my @ReferenceFilterList = $Self->_GetParamReferenceFilterList(
Expand Down Expand Up @@ -587,6 +597,16 @@ sub _ChangeAction {
$FieldConfig{$Name} = $GetParam{$Name};
}

# interdependencies of multiselect, multivalue and editfieldmode
# set multiselect key for consistency in backend
$FieldConfig{Multiselect} = $FieldConfig{EditFieldMode} eq 'Multiselect' ? 1 : 0;

# differentiate only between autocomplete and dropdown
$FieldConfig{EditFieldMode} = $FieldConfig{EditFieldMode} eq 'AutoComplete' ? 'AutoComplete' : 'Dropdown';

# multiselect excludes multivalue
$FieldConfig{MultiValue} = $FieldConfig{Multiselect} ? 0 : $FieldConfig{MultiValue};

$GetParam{ReferenceFilterCounter} = $ParamObject->GetParam( Param => 'ReferenceFilterCounter' ) || 0;

my @ReferenceFilterList = $Self->_GetParamReferenceFilterList(
Expand Down Expand Up @@ -759,6 +779,9 @@ sub _ShowScreen {
Class => 'Modernize W75pc Validate_Number',
);

# compute value for editfieldmode to maintain frontend selection
$Param{EditFieldMode} = $Param{EditFieldMode} eq 'AutoComplete' ? 'AutoComplete' : ( $Param{Multiselect} ? 'Multiselect' : 'Dropdown' );

# Selections may be set up in a declaritive way
for my $Setting ( $Param{FieldTypeSettings}->@* ) {
if ( $Setting->{InputType} eq 'Selection' ) {
Expand Down
10 changes: 5 additions & 5 deletions Kernel/System/DynamicField/Driver/Reference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ sub EditFieldRender {
Class => $FieldClass,
HTMLQuote => 1,
Translation => $DFDetails->{Translation},
PossibleNone => $DFDetails->{PossibleNone},
PossibleNone => 0,
);
}
}
Expand All @@ -367,9 +367,9 @@ sub EditFieldRender {
SelectedID => \@SelectedIDs,
Class => $FieldClass,
HTMLQuote => 1,
Multiple => $DFDetails->{EditFieldMode} eq 'Multiselect' ? 1 : 0,
Multiple => $DFDetails->{Multiselect},
Translation => $DFDetails->{Translation},
PossibleNone => $DFDetails->{PossibleNone},
PossibleNone => 0,
);
}
}
Expand All @@ -384,7 +384,7 @@ sub EditFieldRender {
ObjectType => $DFDetails->{ReferencedObjectType},
);
my @ResultHTML;
for my $ValueIndex ( 0 .. ( $DFDetails->{EditFieldMode} eq 'Multiselect' ? 0 : $#{$Value} ) ) {
for my $ValueIndex ( 0 .. ( $DFDetails->{Multiselect} ? 0 : $#{$Value} ) ) {
my $FieldID = $DFDetails->{MultiValue} ? $FieldName . '_' . $ValueIndex : $FieldName;

if ( !$ValueIndex ) {
Expand Down Expand Up @@ -438,7 +438,7 @@ sub EditFieldRender {
ID => $FieldTemplateData{FieldID},
Class => $FieldClass,
HTMLQuote => 1,
Multiple => $DFDetails->{EditFieldMode} eq 'Multiselect' ? 1 : 0,
Multiple => $DFDetails->{Multiselect},
Translation => $DFDetails->{TranslatableValues} || 0,
);
$TemplateHTML = $Param{LayoutObject}->Output(
Expand Down

0 comments on commit 7b861f2

Please sign in to comment.