Skip to content

Fix initial primitive value #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
find from items
  • Loading branch information
akkaradej committed Jul 5, 2023
commit a4882d61eda94d5a9a9ba84655a042af8bde055e
16 changes: 10 additions & 6 deletions src/lib/Select.svelte
Original file line number Diff line number Diff line change
@@ -85,16 +85,20 @@

function setValue() {
if (typeof value === 'string') {
let item = (items || []).find((item) => item[itemId] === value);
value = item || {
[itemId]: value,
label: value,
};
value = findOrCreateObject(value);
} else if (multiple && Array.isArray(value) && value.length > 0) {
value = value.map((item) => (typeof item === 'string' ? { [itemId]: item, label: item } : item));
value = value.map((item) => (typeof item === 'string' ? findOrCreateObject(item) : item));
}
}

function findOrCreateObject(value) {
let item = (items || []).find((item) => item[itemId] === value);
return item || {
[itemId]: value,
label: value,
};
}

let _inputAttributes;
function assignInputAttributes() {
_inputAttributes = Object.assign(