Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

Not translated yet

This page has not been translated into English yet, so it is shown in Spanish.

FormField

interfaz Since 1.5.0 No import

Un campo de un Form, como lo devuelve form.field(name): lo necesario para que un componente de campo propio enlace su control, su etiqueta y su mensaje sin recibir el formulario entero. id y los demás IDs salen de useId, así que coinciden entre SSR e hidratación y no se repiten entre formularios.

Se autoimporta en los componentes y en app/.

ts
import type { FormField } from "@meekojs/meeko/framework";

Source code src/app/composables/useForm.ts:227

Declaración #

ts
interface FormField<Value> {
	readonly name: string
	readonly id: string
	readonly errorId: string
	readonly hintId: string
	readonly value: Signal<Value>
	readonly error: ReadonlySignal<string | undefined>
	readonly invalid: ReadonlySignal<boolean>
	readonly describedBy: ReadonlySignal<string | undefined>
}

Type parameters #

Value

Tipo del valor del campo.

Example #

meeko
<!-- app/components/AppField.meeko -->
<script lang="ts">
import type { FormField } from "@meekojs/meeko/framework";
const props = defineProps<{ field: FormField<string>; label: string; type?: string; hint?: string }>();
const describedBy = computed(() => [props.hint ? props.field.hintId : "", props.field.describedBy.value ?? ""].filter(Boolean).join(" ") || null);
</script>
<template>
  <label bind:for="props.field.id">{props.label}</label>
  <input bind:id="props.field.id" bind:name="props.field.name" bind:type="props.type ?? 'text'" model="props.field.value"
    bind:aria-invalid="props.field.invalid.value ? 'true' : null" bind:aria-describedby="describedBy.value">
  <p if:when="props.hint" bind:id="props.field.hintId">{props.hint}</p>
  <p if:when="props.field.error.value" bind:id="props.field.errorId">{props.field.error.value}</p>
</template>
meeko
<AppField bind:field="form.field('email')" label="Correo" type="email" />

Propiedades #

name #

propiedad sólo lectura

readonly name: string

Nombre del campo en el formulario, para el atributo name del control.

id #

propiedad sólo lectura

readonly id: string

ID del control, para su id y el for de su <label>.

errorId #

propiedad sólo lectura

readonly errorId: string

ID del mensaje de error (${id}-error).

hintId #

propiedad sólo lectura

readonly hintId: string

ID de un texto de ayuda (${id}-hint), para aria-describedby.

value #

propiedad sólo lectura

readonly value: Signal<Value>

La misma señal escribible que form.fields[name], para model.

error #

propiedad sólo lectura

readonly error: ReadonlySignal<string | undefined>

Primer mensaje de error del campo (o de una ruta anidada, como items.0.name), o undefined.

invalid #

propiedad sólo lectura

readonly invalid: ReadonlySignal<boolean>

true si el campo tiene algún error.

describedBy #

propiedad sólo lectura

readonly describedBy: ReadonlySignal<string | undefined>

errorId mientras el campo tiene un error, o undefined: el valor de aria-describedby.

See also #

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: packages/meeko/src/app/composables/useForm.ts