Form / foldkit-mixins-form

FormView

namespace · packages/mixins-form/src/index.ts:768

const FormView = { field, define, fields, submodel }

In the guides

Members

FormView.field

function · packages/mixins-form/src/index.ts:643

field<
  Key extends string,
  Model,
  Message extends {
    readonly _tag: string
  },
>(
  form: FormLike<Key, Model, Message>,
  options?: {
    readonly renderers?: Renderers<Message>
    readonly attrs?: {
      readonly [K in Key]?: FieldAttrs
    }
  },
): FieldView<Key, Message>

The view of one field, to style or extend before handing it to FormView.define.

FormView.define

function · packages/mixins-form/src/index.ts:776

define<
  Key extends string,
  Model,
  Message extends {
    readonly _tag: string
  },
>(
  form: FormLike<Key, Model, Message> & {
    readonly bundle: {
      readonly name: string
    }
  },
  options?: {
    readonly field?: FieldView<Key, Message>
    readonly renderers?: Renderers<Message>
  },
): SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>

The view of the whole form: each control through field, in the input's order, a hidden key left out. Pass a styled field to change how fields look; attach Style and Behavior to the result to change the form around them.

FormView.fields

function · packages/mixins-form/src/index.ts:936

fields<
  Key extends string,
  Model,
  FormMessage extends {
    readonly _tag: string
  },
>(
  form: FormLike<Key, Model, FormMessage> & {
    readonly bundle: {
      readonly name: string
    }
  },
  options?: {
    readonly field?: FieldView<Key, FormMessage>
    readonly renderers?: Renderers<FormMessage>
  } & FieldsOptions<Key, FormMessage>,
): {
  readonly view: SlotView.SlotView<
    typeof FormSlots,
    FormInput<Model, Key>,
    FormMessage
  >
  readonly field: FieldsField<Key, Model, FormMessage>
}

The whole form, as define draws it, with per-key overrides; and one flat key's control, for a layout the caller owns. Keys with no override render through the base field view (a new key of a known kind needs nothing new), each through its style when one is given and with its element attrs. field draws through the base view with a form-universe h, or through the override it is given, with any h. Nested keys and Bundle-backed keys draw only through view (or an override); field without one refuses them, naming the key.

FormView.submodel

function · packages/mixins-form/src/index.ts:1044

submodel<
  Key extends string,
  Model extends {
    readonly errors: ReadonlyArray<string>
    readonly submitPending: boolean
  },
  Message extends {
    readonly _tag: string
  },
>(
  form: FormLike<Key, Model, Message>,
  view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>,
  options?: {
    readonly canSubmit?: (model: Model) => boolean
  },
): Submodel.View<Model, Message, FormViewInputs<Key>>

For Bundle.withView: the Submodel view that draws view, so a placement renders the form with placed.view(model, h, { options }).

ts
const Drawn = EditPost.bundle.pipe(Bundle.withView(FormView.submodel(EditPost, View)))