1. Meta Elements
  2. Object

Meta Elements

Object

Object element

Configuration

The object element inherits all the attributes of BaseElement

In addition, it has the following attributes:

Attribute Required Description Type Example
name Yes Name of the field string user
schema Yes Validation schema ZodObject zod.object({})
elements Yes The sub-elements schema Element[] [{type: 'header', text: 'Hello'}]

Example

{}
SVELTE
<script lang="ts">
  import { Base, Form } from '$lib';
  import * as zod from 'zod';

  const form = Base.newForm([
    {
      type: 'object',
      name: 'user',
      schema: zod.object({}),
      elements: [
        {
          type: 'input',
          name: 'name',
          label: 'Name',
          schema: zod.string()
        },
        {
          type: 'input',
          name: 'email',
          label: 'Email',
          schema: zod.string().email()
        }
      ]
    }
  ] as const);

  const data = form.getData();
</script>

<Form {form} />

<pre>{JSON.stringify($data, null, 4)}</pre>