mirror of
https://github.com/pinry/pinry.git
synced 2026-02-28 01:01:07 +01:00
Feafactor: Move AutoComplete filter function as utils
This commit is contained in:
@@ -38,21 +38,10 @@
|
||||
<script>
|
||||
import API from '../api';
|
||||
import ModelForm from '../utils/ModelForm';
|
||||
import AutoComplete from '../utils/AutoComplete';
|
||||
|
||||
const fields = ['name'];
|
||||
|
||||
function getFilteredOptions(options, filterText) {
|
||||
return options.filter(
|
||||
(option) => {
|
||||
const index = option.name
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.indexOf(filterText.toLowerCase());
|
||||
return index >= 0;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function getBoardFromResp(boardObject) {
|
||||
return { name: boardObject.name, value: boardObject.id };
|
||||
}
|
||||
@@ -62,7 +51,7 @@ function getAvailableOptions(vm, filter) {
|
||||
if (filter === '' || filter === null) {
|
||||
availableOptions = vm.allOptions;
|
||||
} else {
|
||||
availableOptions = getFilteredOptions(
|
||||
availableOptions = AutoComplete.getFilteredOptions(
|
||||
vm.allOptions, vm.form.name.value,
|
||||
);
|
||||
}
|
||||
|
||||
15
pinry-spa/src/components/utils/AutoComplete.js
Normal file
15
pinry-spa/src/components/utils/AutoComplete.js
Normal file
@@ -0,0 +1,15 @@
|
||||
function getFilteredOptions(options, filterText) {
|
||||
return options.filter(
|
||||
(option) => {
|
||||
const index = option.name
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.indexOf(filterText.toLowerCase());
|
||||
return index >= 0;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
getFilteredOptions,
|
||||
};
|
||||
Reference in New Issue
Block a user