diff --git a/src/components/create.svelte b/src/components/create.svelte index af165c5..436c6e4 100644 --- a/src/components/create.svelte +++ b/src/components/create.svelte @@ -21,13 +21,13 @@ $: abbForm = { shortform: '', phrase: '', - target: '', + target: { value: -1 }, errors: [] }; let importing = false; let progress = 0; - const handleCreate = async (e: Any) => { + const handleCreate = async (e: Event) => { // abbForm.errors = [] e.preventDefault(); @@ -41,7 +41,8 @@ remind: number, // negative if disabled updated: Date; */ - const sf = { + var sf = { + id: null, listid: abbForm.target.value, shortform: abbForm.shortform.replace(/\s/g, '').toLowerCase(), phrase: abbForm.phrase.trim(), @@ -56,11 +57,13 @@ .equals([sf.listid, sf.shortform]) .first() .then((existing) => { - sf.id = existing.id; - db.shortforms.put(sf).then((result) => { - cacheShortform(sf); - appState.open = ''; - }); + if (existing?.id) { + sf.id = Number(existing.id); + db.shortforms.put(sf).then((result) => { + cacheShortform(sf); + appState.open = ''; + }); + } }) .catch(() => { db.shortforms.put(sf).then((result) => { @@ -81,17 +84,18 @@ }; const onSelectedChange = (v) => { - // console.log(v); + console.log(typeof v, v); abbForm.target = v; }; + $: selectedLists = { - standard: {}, - subject: {} + standard: { label: '', value: -1 }, + subject: { label: '', value: -1 } }; let show = false; db.lists - .get(shortforms.standardList) + .get(shortforms.standardList.id) .then((l) => { if (l) { selectedLists.standard = { value: l.id, label: l.name }; @@ -104,7 +108,7 @@ console.error('db.lists.get (standard)', err); }); db.lists - .get(shortforms.subjectList) + .get(shortforms.subjectList.id) .then((l) => { if (l) { selectedLists.subject = { value: l.id, label: l.name }; @@ -159,13 +163,7 @@ >
Fel vid import