Form / foldkit-mixins-form

Style custom Slots and pass picker options

Attach your own classes directly to FieldSlots and FormSlots using Style.whenInput, then pass options and words when drawing the placed Bundle (EditForm from Bundle.declare(Drawn, 'form')):

ts
import type { FieldInput } from 'foldkit-mixins-form'

const CustomField = FormView.field(Edit).pipe(
  Style.attach(
    Style.forSlots(FieldSlots)({
      root: Style.class('field'),
      text: Style.whenInput<FieldInput>(input => input.invalid, Style.class('is-invalid')),
    }),
  ),
)

const CustomView = FormView.define(Edit, { field: CustomField }).pipe(
  Style.attach(Style.forSlots(FormSlots)({ root: Style.class('form') })),
)

Where the parent view draws the placed form (model and h are the parent's view arguments, authors the loaded picker data):

ts
EditForm.view(model, h, {
  options: { editorId: authors.map(author => ({ value: author.id, label: author.name })) },
  words: { submit: 'Save' },
})

Additional view options:

  • submits: false omits the submit button (useful when a role may edit drafts without submitting).
  • locked: ['ownerId'] renders those keys disabled (and includes hidden inputs so non-JS form posts keep their values; the server must still authorize writes). Bundle-backed controls inside a locked key render inside a disabled <fieldset>.
  • options supplies { value, label } choices for RelationOne and RelationMany pickers loaded by your application.
  • Hidden controls render no DOM element.