first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<script lang="ts">
|
||||
import groupStore from "../stores/group";
|
||||
|
||||
export let value = "";
|
||||
export let name = "";
|
||||
|
||||
$: {
|
||||
if ($groupStore.stale && !$groupStore.loading) {
|
||||
groupStore.load();
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($groupStore.groups.length > 0 && value === "") {
|
||||
const nonEmpty = $groupStore.groups.find(g => g.items.length > 0);
|
||||
if (nonEmpty != null) {
|
||||
value = nonEmpty.items[0].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<select name={name} bind:value={value} disabled={$groupStore.loading}>
|
||||
{#each $groupStore.groups as group (group.id)}
|
||||
<optgroup label={group.name}>
|
||||
{#each group.items as item (item.id)}
|
||||
<option value={item.id} selected={item.id === value}>{item.name} ({item.groupWeight})</option>
|
||||
{/each}
|
||||
</optgroup>
|
||||
{/each}
|
||||
</select>
|
||||
Reference in New Issue
Block a user