Skip to content

Commit 2539002

Browse files
committed
#26 add case return target as simple id
1 parent 39e6bb0 commit 2539002

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

src/lib/components/form/DropdownKvP.svelte

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export let invalid = false;
1010
export let feedback = [''];
1111
export let required = false;
12+
export let targetIsComplex = false;
1213
1314
$: selected = null;
1415
@@ -17,12 +18,26 @@
1718
1819
function updatedSelectedValue(selection) {
1920
if (selection != null) {
20-
selected = selection.id;
21+
if(targetIsComplex)
22+
{
23+
selected = selection.id;
24+
}
25+
else
26+
{
27+
selected = selection
28+
}
2129
}
2230
}
2331
2432
function updatedTarget(id) {
25-
target = source.find((opt) => opt.id === id);
33+
if(targetIsComplex)
34+
{
35+
target = source.find((opt) => opt.id === id);
36+
}
37+
else
38+
{
39+
target = id;
40+
}
2641
}
2742
</script>
2843

src/lib/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ export type {
5555
user,
5656
Input,
5757
FileUploaderModel,
58-
Link
59-
} from './models/Models.js';
58+
Link,
59+
ListItem,
60+
KvP
61+
} from './models/Models.js';
62+
63+
//enum
64+
export { Position } from './models/Enums';
6065

6166
// Table
6267
export { Table, TableFilter, columnFilter, searchFilter };

src/routes/components/form/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import InputValidationJsRaw from './examples/inputvalidation?raw';
2222
2323
// example 4 - validation
24-
import { Metadatastructures } from './examples/exampleData';
24+
import { Metadatastructures, Decimals } from './examples/exampleData';
2525
import DropdownKvpExample from './examples/DropdownKVPExample.svelte';
2626
import DropdownKVPExampleRaw from './examples/DropdownKVPExample.svelte?raw';
2727

src/routes/components/form/examples/DropdownKVPExample.svelte

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { CodeBlock } from '@skeletonlabs/skeleton';
55
66
$: target = { id: 2, text: 'gbif' };
7+
$: simpleTarget = 2;
78
89
import { Metadatastructures } from './exampleData';
910
@@ -12,7 +13,23 @@
1213
}
1314
</script>
1415

16+
17+
1518
<div class="grid gap-10">
19+
20+
<h4 class="h4">Target is simple</h4>
21+
<DropdownKvP
22+
id="metadataStructure"
23+
title="Metadata Structure"
24+
bind:target={simpleTarget}
25+
source={Metadatastructures}
26+
on:change={onChangeHandler}
27+
targetIsComplex = {false}
28+
/>
29+
30+
<CodeBlock language="ts" code={JSON.stringify(simpleTarget, undefined, 2)} />
31+
32+
<h4 class="h4">Target is complex</h4>
1633
<DropdownKvP
1734
id="metadataStructure"
1835
title="Structure"
@@ -22,4 +39,5 @@
2239
/>
2340

2441
<CodeBlock language="ts" code={JSON.stringify(target, undefined, 2)} />
42+
2543
</div>

src/routes/components/form/examples/exampleData.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ export const Datastructures = [
2828
}
2929
];
3030

31+
export const Decimals = [
32+
{
33+
id: 44,
34+
text: 'comma'
35+
},
36+
{
37+
id: 46,
38+
text: 'point'
39+
}
40+
];
41+
42+
3143
export const CountrieNames = [
3244
'United States',
3345
'Canada',
@@ -515,3 +527,5 @@ export const Countries = [
515527
{ name: 'Zambia', code: 'ZM' },
516528
{ name: 'Zimbabwe', code: 'ZW' }
517529
];
530+
531+

0 commit comments

Comments
 (0)