From 5c94aca7b2185ac412a97574891621bf5ded20aa Mon Sep 17 00:00:00 2001 From: Beiwinkler Date: Tue, 11 Jul 2023 16:07:21 +0200 Subject: [PATCH 1/4] Select Values per Key or per Value when Key ist not set --- ...completeMultiselect - Verkn\303\274pfung.lnk" | Bin 0 -> 1015 bytes src/AutocompleteMultiselect.jsx | 8 ++++---- src/components/AutocompleteUI.jsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 "mendix-AutocompleteMultiselect - Verkn\303\274pfung.lnk" diff --git "a/mendix-AutocompleteMultiselect - Verkn\303\274pfung.lnk" "b/mendix-AutocompleteMultiselect - Verkn\303\274pfung.lnk" new file mode 100644 index 0000000000000000000000000000000000000000..fcf864bd97100031096d5c5e03ab61777a8fce66 GIT binary patch literal 1015 zcmbtST}TvB6#mv0Qi)p8Orl&93QJtZ@}(t1+f_Ge)!J4J=D}rV!qxrDnZ;!($)dng z1H-p|Oe_ofrJ`Pnh3F-Ekcv=42!fEL#OOik_q($sy%l(e@7#ONx#wrTbN2$Ugy6L3flD@wv?;sEM#&->4MIW6(+wgcM zN+sz+9vsI8O7mZ7=aRL9?E^9A^UT|)P;N%eG<8R8@YdA3cQ<#@6hRiOn0+$S)EN;z z2X7VrSVp;gu}b>TW9>#58Y5H$kw6)$5r=^&6e5fmLi8Ghm-Y}(LFm+kRiOqH5FNxi zLi~x?w-I6;Ce{$5^1^XnzF@<5(08E53zt*&>sp69UfZaE39tS)rh8~HDEeX;yXQ_z3bMq zOa1j{=Zn8Ry7qL={yArO!L#Lk*M}qj^4mGiEMQ3dMY*rh_epv@=|WH4==@mjh<>Qp zPrE9L*@+E=o0PSarZk~~v?7$i1t(q!H zX_aq9Gbb*hR}yCQ;-jX1oe=$BZBt4r2Vdqqc!N~KM8Q}e?S+Jyc_;V(rA9WXRsNz@ zCxJ`-dtf_z5RKl=54&&n#XO^)D#u7=qIW&*tpq$o^VFBg9l8B`&Top|zx+1)sIdQ8 FzX4Z-@S^|# literal 0 HcmV?d00001 diff --git a/src/AutocompleteMultiselect.jsx b/src/AutocompleteMultiselect.jsx index ee65410..71a1b89 100644 --- a/src/AutocompleteMultiselect.jsx +++ b/src/AutocompleteMultiselect.jsx @@ -66,17 +66,17 @@ export default class AutocompleteMultiselect extends Component { ? this.optionsSelected : this.optionsSelected === null ? [] : [this.optionsSelected]; const optionsSelectedNotInList = optionsSelectedAsArray.filter(selectedOption => { - return dataParsed.find(option => option.title === selectedOption.title && option.key === selectedOption.key) === undefined; + return dataParsed.find(option => (option.key.length > 0 || option.title === selectedOption.title) && option.key === selectedOption.key) === undefined; }); dataParsed = dataParsed.concat(optionsSelectedNotInList); } else { if (this.props.multiple) { // Else check if optionSelected are still available. This is done since it can be the case that the options have been changed. this.optionsSelected = this.optionsSelected.filter(selectedOption => { - return dataParsed.find(option => option.title === selectedOption.title && option.key === selectedOption.key) !== undefined; + return dataParsed.find(option => (option.key.length > 0 || option.title === selectedOption.title) && option.key === selectedOption.key) !== undefined; }); } else if (this.optionsSelected !== null) { - this.optionsSelected = dataParsed.find(option => option.title === this.optionsSelected.title && option.key === this.optionsSelected.key); + this.optionsSelected = dataParsed.find(option => (option.key.length > 0 || option.title === this.optionsSelected.title) && option.key === this.optionsSelected.key); } if (this.optionsSelected === undefined) { this.optionsSelected = null; } @@ -149,7 +149,7 @@ export default class AutocompleteMultiselect extends Component { } else { // Else check if option is selected (based on the title). This is done since it can be the case that the options have been changed. if (multiSelect) { - if (this.optionsSelected.find(option => option.title === optionTitle)) { + if (this.optionsSelected.find(findoption => (option.key.length > 0 || option.title === value.title) && findoption.key === option.key)) { optionsSelected.push(option); } } else if (this.optionsSelected !== null) { diff --git a/src/components/AutocompleteUI.jsx b/src/components/AutocompleteUI.jsx index 37df501..38a0414 100644 --- a/src/components/AutocompleteUI.jsx +++ b/src/components/AutocompleteUI.jsx @@ -23,7 +23,7 @@ export class AutocompleteUI extends Component { loading = {this.props.loading} loadingText = {this.props.loadingText} onInputChange={ this.props.onInputChange} - getOptionSelected={(option, value) => option.title === value.title && option.key === value.key} + getOptionSelected={(option, value) => (option.key.length> 0 || option.title === value.title) && option.key === value.key} renderOption={(option, { selected }) => ( {this.props.showCheckboxes ? Date: Wed, 12 Jul 2023 14:18:55 +0200 Subject: [PATCH 2/4] Remove issue when no key is defined --- src/AutocompleteMultiselect.jsx | 8 ++++---- src/components/AutocompleteUI.jsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AutocompleteMultiselect.jsx b/src/AutocompleteMultiselect.jsx index 71a1b89..698a635 100644 --- a/src/AutocompleteMultiselect.jsx +++ b/src/AutocompleteMultiselect.jsx @@ -66,17 +66,17 @@ export default class AutocompleteMultiselect extends Component { ? this.optionsSelected : this.optionsSelected === null ? [] : [this.optionsSelected]; const optionsSelectedNotInList = optionsSelectedAsArray.filter(selectedOption => { - return dataParsed.find(option => (option.key.length > 0 || option.title === selectedOption.title) && option.key === selectedOption.key) === undefined; + return dataParsed.find(option => ((option.key !== undefined && option.key.length > 0) || option.title === selectedOption.title) && option.key === selectedOption.key) === undefined; }); dataParsed = dataParsed.concat(optionsSelectedNotInList); } else { if (this.props.multiple) { // Else check if optionSelected are still available. This is done since it can be the case that the options have been changed. this.optionsSelected = this.optionsSelected.filter(selectedOption => { - return dataParsed.find(option => (option.key.length > 0 || option.title === selectedOption.title) && option.key === selectedOption.key) !== undefined; + return dataParsed.find(option => ((option.key !== undefined && option.key.length > 0) || option.title === selectedOption.title) && option.key === selectedOption.key) !== undefined; }); } else if (this.optionsSelected !== null) { - this.optionsSelected = dataParsed.find(option => (option.key.length > 0 || option.title === this.optionsSelected.title) && option.key === this.optionsSelected.key); + this.optionsSelected = dataParsed.find(option => ((option.key !== undefined && option.key.length > 0) || option.title === this.optionsSelected.title) && option.key === this.optionsSelected.key); } if (this.optionsSelected === undefined) { this.optionsSelected = null; } @@ -149,7 +149,7 @@ export default class AutocompleteMultiselect extends Component { } else { // Else check if option is selected (based on the title). This is done since it can be the case that the options have been changed. if (multiSelect) { - if (this.optionsSelected.find(findoption => (option.key.length > 0 || option.title === value.title) && findoption.key === option.key)) { + if (this.optionsSelected.find(findoption => (option.key.length > 0 || findoption.title === optionTitle) && findoption.key === option.key)) { optionsSelected.push(option); } } else if (this.optionsSelected !== null) { diff --git a/src/components/AutocompleteUI.jsx b/src/components/AutocompleteUI.jsx index 38a0414..b8ba1f3 100644 --- a/src/components/AutocompleteUI.jsx +++ b/src/components/AutocompleteUI.jsx @@ -23,7 +23,7 @@ export class AutocompleteUI extends Component { loading = {this.props.loading} loadingText = {this.props.loadingText} onInputChange={ this.props.onInputChange} - getOptionSelected={(option, value) => (option.key.length> 0 || option.title === value.title) && option.key === value.key} + getOptionSelected={(option, value) => ((option.key !== undefined && option.key.length > 0) || option.title === value.title) && option.key === value.key} renderOption={(option, { selected }) => ( {this.props.showCheckboxes ? Date: Wed, 12 Jul 2023 14:21:03 +0200 Subject: [PATCH 3/4] Remove issue when no key is defined --- src/AutocompleteMultiselect.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AutocompleteMultiselect.jsx b/src/AutocompleteMultiselect.jsx index 698a635..ba7663c 100644 --- a/src/AutocompleteMultiselect.jsx +++ b/src/AutocompleteMultiselect.jsx @@ -149,7 +149,7 @@ export default class AutocompleteMultiselect extends Component { } else { // Else check if option is selected (based on the title). This is done since it can be the case that the options have been changed. if (multiSelect) { - if (this.optionsSelected.find(findoption => (option.key.length > 0 || findoption.title === optionTitle) && findoption.key === option.key)) { + if (this.optionsSelected.find(findoption => ((option.key !== undefined && option.key.length > 0) || findoption.title === optionTitle) && findoption.key === option.key)) { optionsSelected.push(option); } } else if (this.optionsSelected !== null) { From df330f224b8b34949db80cab519a7c7c8ac98a8b Mon Sep 17 00:00:00 2001 From: Beiwinkler Date: Wed, 12 Jul 2023 14:32:09 +0200 Subject: [PATCH 4/4] Remove issue when no key is defined --- src/AutocompleteMultiselect.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AutocompleteMultiselect.jsx b/src/AutocompleteMultiselect.jsx index ba7663c..e04f838 100644 --- a/src/AutocompleteMultiselect.jsx +++ b/src/AutocompleteMultiselect.jsx @@ -149,7 +149,7 @@ export default class AutocompleteMultiselect extends Component { } else { // Else check if option is selected (based on the title). This is done since it can be the case that the options have been changed. if (multiSelect) { - if (this.optionsSelected.find(findoption => ((option.key !== undefined && option.key.length > 0) || findoption.title === optionTitle) && findoption.key === option.key)) { + if (this.optionsSelected.find(findoption => ((findoption.key !== undefined && option.key.length > 0) || findoption.title === optionTitle) && findoption.key === option.key)) { optionsSelected.push(option); } } else if (this.optionsSelected !== null) {