fix: remove checking buf until I can figure out how to not use buf.lock
This commit is contained in:
@ -1,31 +1,31 @@
|
||||
import { getContext, hasContext, setContext } from 'svelte';
|
||||
|
||||
type Item = {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
const key = 'form';
|
||||
export function setFormContext(id: string, name: string) {
|
||||
const item = getFormContext();
|
||||
if (!item) {
|
||||
const item: Item = $state({
|
||||
id,
|
||||
name,
|
||||
});
|
||||
setContext(key, item);
|
||||
const item = getFormContext();
|
||||
if (!item) {
|
||||
const item: Item = $state({
|
||||
id,
|
||||
name
|
||||
});
|
||||
setContext(key, item);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
item.id = id;
|
||||
item.name = name;
|
||||
item.id = id;
|
||||
item.name = name;
|
||||
}
|
||||
|
||||
export function getFormContext() {
|
||||
if (!hasContext(key)) {
|
||||
return null;
|
||||
}
|
||||
if (!hasContext(key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getContext(key) as Item;
|
||||
}
|
||||
return getContext(key) as Item;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
<div bind:this={ref} class={cn('text-red text-sm', className)} {...restProps}>
|
||||
{#if errors && Array.isArray(errors)}
|
||||
{#each errors as error}
|
||||
{#each errors as error (error)}
|
||||
<label for={item?.id}>{error.message}</label>
|
||||
{/each}
|
||||
{:else if errors}
|
||||
|
@ -16,6 +16,6 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div bind:this={ref} class={cn('flex flex-col gap-1')} {...restProps}>
|
||||
<div bind:this={ref} class={cn('flex flex-col gap-1', className)} {...restProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
|
@ -2,8 +2,4 @@ import Field from './field.svelte';
|
||||
import Errors from './errors.svelte';
|
||||
import Label from './label.svelte';
|
||||
|
||||
export {
|
||||
Field,
|
||||
Errors,
|
||||
Label
|
||||
};
|
||||
export { Field, Errors, Label };
|
||||
|
Reference in New Issue
Block a user