Hoppa till innehåll
Markdown

CustomList

A sortable list of items with configurable modal content. Each item has a unique ID and can hold its own field values.

Custom list
  • Test 1
  • Test 2
  • Test 3

The children snippet receives an item draft. Use item.id to namespace fields.

CustomList uses the first eligible input or textarea value as the name shown in the list, falling back to the item ID.

App.svelte
<script>
import { CustomList, Input, PageSelector, Panel } from '@soleil-se/config-svelte';
</script>
<Panel heading="Settings">
<CustomList name="customList" label="Custom list">
{#snippet children({ id })}
<Input name="{id}.name" label="Name" required />
<PageSelector name="{id}.page" label="Page" />
{/snippet}
</CustomList>
</Panel>

Bind an input’s value to item.name when you want that value to control the displayed item name, overriding the first-field fallback.
Do not use destructuring to extract id or name from item in the snippet, as it will break reactivity.

App.svelte
<script>
import { CustomList, Input } from '@soleil-se/config-svelte';
</script>
<CustomList name="customList" label="Custom list">
{#snippet children(item)}
<Input name="{item.id}.title" label="Title" />
<Input name="{item.id}.displayName" label="Name shown in the list" bind:value={item.name} />
{/snippet}
</CustomList>

You can extract the snippet content to a separate Svelte component for better organization and reusability.

App.svelte
<script>
import { CustomList } from '@soleil-se/config-svelte';
import CustomListItem from './CustomListItem.svelte';
</script>
<CustomList name="customList" label="Custom list">
{#snippet children(item)}
<CustomListItem {item} />
{/snippet}
</CustomList>
CustomListItem.svelte
<script>
import { Input, PageSelector } from '@soleil-se/config-svelte';
let { item } = $props();
</script>
<Input name="{item.id}.title" label="Title" />
<PageSelector name="{item.id}.page" label="Page" />

With the standard save behavior, the list’s name stores the ordered item IDs. Child field names use each ID as a prefix, so the saved fields can be read by combining the item ID with the field name.

index.js
import appData from '@sitevision/api/server/appData';
function getCustomList() {
return appData.getArray('customList')?.map((id) => ({
name: appData.get(`${id}.name`),
pageUri: appData.get(`${id}.page`, 'URI'),
})) || [];
}
PropTypeDescription
label
required
string | Snippet

Field label, a string or Svelte snippet.

value
$bindable
string[]

Ordered item IDs.

Default: []
values
$bindable
object
{ [key: string]: { [key: string]: unknown } }

Committed field values keyed by item ID. Draft edits are published when the item is saved.

Default: {}
name
string

Configuration key for the ordered item IDs. It is also used as the prefix when generating item IDs.

description
string | Snippet

Description shown below the field, a string or Svelte snippet.

required
boolean

Requires at least one item.

Default: false
disabled
boolean

Disables adding, editing, removing, and reordering items.

Default: false
show
boolean

Shows or hides the list without destroying it.

Default: true
icon
string

Sitevision icon class displayed for list items.

class
string

CSS class added to the form-group wrapper.

Default: ''
children
Snippet<[item: ItemDraft]>
{ id: string, name: string, values: ItemValues, ready: () => Promise<void> }

Snippet rendered in each item’s modal. It receives a writable item draft.

onChange
function
(value: string[], values: Values) => void

Called after a committed list change with the ordered IDs and committed field values.

validate
function
(context: ValidationContext<string[]>) => ValidationResult

Custom validator for the ordered item IDs.

Each children snippet receives an ItemDraft with:

  • id: unique ID for the item. Use it as a prefix for each item’s field name, for example "{item.id}.page".
  • name: writable display name. Binding a field’s value to item.name explicitly controls the item name. Otherwise, the first eligible input or textarea value is used, with the ID as a fallback.
  • values: writable record for the item’s custom field values.
  • ready(): refreshes the list item’s name and presentation after asynchronous data is ready. Call it when the item modal is closed and settled.

Each item is edited in a modal. Save validates and commits the item; canceled edits are not committed to the list’s value or values.

When managing configuration data yourself, bind value to the ordered item IDs and values to the field-value map. Register the complete object with onSave:

<script>
import { CustomList, Input, Panel } from '@soleil-se/config-svelte';
import { onSave } from '@soleil-se/config-svelte/utils';
let { values } = $props();
onSave(() => values);
</script>
<Panel heading="Settings">
<CustomList
label="Custom list"
bind:value={values.customList}
bind:values={values.customListValues}
>
{#snippet children(item)}
<Input label="Name" bind:value={item.name} />
<Input label="Description" bind:value={item.values.description} />
{/snippet}
</CustomList>
</Panel>

Call the ready() method on an item draft to refresh its name and presentation after asynchronous data is available. This ensures that the list row reflects the latest item state.

<script>
import { CustomList, Panel } from '@soleil-se/config-svelte';
import Item from './Item.svelte';
</script>
<Panel heading="Settings">
<CustomList label="Custom list">
{#snippet children(item)}
<Item {item} />
{/snippet}
</CustomList>
</Panel>
Item.svelte
<script>
import { onMount } from 'svelte';
import { Input } from '@soleil-se/config-svelte';
let { item } = $props();
onMount(async () => {
item.name = await someAsyncFunction(); // Replace with actual asynchronous data
item.ready();
});
</script>
<Input name="{item.id}.name" label="Name" value={item.name} readonly />
<Input name="{item.id}.description" label="Description" />

Use CustomListItemTemplate for custom static markup in the displayed list row. Its markup is copied into the row when an item is initialized, saved, or marked ready; bindings and event handlers are not retained.

<script>
import { CustomList, CustomListItemTemplate, Input } from '@soleil-se/config-svelte';
</script>
<CustomList name="customList" label="Custom list">
{#snippet children(item)}
<CustomListItemTemplate>
<strong>{item.name}</strong>
</CustomListItemTemplate>
<Input name="{item.id}.name" label="Name" bind:value={item.name} />
{/snippet}
</CustomList>

By default, the component applies standard required-field validation. A custom validate prop replaces that default and returns { success: boolean, message?: string }.
Validation errors are displayed below the component and prevent saving.

See validation for more details.