Saltearse al contenido

setError

Esta página aún no está disponible en tu idioma.

The setError function is used to set the error of a field. It’s useful when you want to set an error programmatically, for example, when you want to set an error from a server response.

Example

<script lang="ts">
import { onMount } from 'svelte';
import { faivform } from '@tuentyfaiv/svelte-form';
const form = faivform<Data>({
// ...config
});
const { setError } = $form;
onMount(async () => {
try {
const response = await fetch('https://api.example.com/user');
const data = await response.json();
} catch (error) {
setError('name', 'The user could not be loaded');
}
});
</script>