Skip to content

Commit

Permalink
fix: .map(Number) creates problems if preselect is not an id but a st…
Browse files Browse the repository at this point in the history
…ring (#206)

* fix: .map(Number) creates problems if preselect is not an id but a string

this is checking if filterGroups in fieldConfig contains 'relation' and only then maps to Number. This could still cause an issue, if a field contains ids and strings. 
I couldn't find a usecase for this, but something to think about.
Another solution would be to cast the key in FilterGroupHelper->getGroupValuesForFilterGroup to string and we can remove the map function altogether. Function is only used in the pimcore_ecommerceframework_index_getvaluesforfilterfield route and therefor should not cause other problems

* Introduce method for preselect value

---------

Co-authored-by: mattamon <[email protected]>
  • Loading branch information
MercuryKojo and mattamon authored Oct 31, 2024
1 parent 245c9a7 commit c3223f1
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec
load: function(store) {
if(this.data) {
if(this.preSelectCombobox.rendered) {
this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number));
this.preSelectCombobox.setValue(this.getPreselectValue());
} else {
this.preSelectCombobox.addListener("afterRender", function() {
this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number));
this.preSelectCombobox.setValue(this.getPreselectValue());
}.bind(this));
}
}
Expand Down Expand Up @@ -239,10 +239,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec

if(this.fieldConfig.multiPreSelect == 'local_single' || this.fieldConfig.multiPreSelect == 'local_multi') {
if(this.preSelectCombobox.rendered) {
this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number));
this.preSelectCombobox.setValue(this.getPreselectValue());
} else {
this.preSelectCombobox.addListener("afterRender", function() {
this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number));
this.preSelectCombobox.setValue(this.getPreselectValue());
}.bind(this));
}
}
Expand All @@ -262,5 +262,12 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec

isDirty: function() {
return this.fieldsCombobox.isDirty() || (this.preSelectCombobox && this.preSelectCombobox.isDirty());
},

getPreselectValue: function() {
if(this.fieldConfig.filterGroups?.includes('relation')) {
return this.data.preSelect?.split(',').map(Number);
}
return this.data.preSelect?.split(',');
}
});

0 comments on commit c3223f1

Please sign in to comment.