You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
794 B

<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>