morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::forms::FormModel Class Reference

The immutable runtime model of one action's form. More...

#include <field_model.hpp>

Public Member Functions

FormModel withSubmitMode (SubmitMode mode) const
 The same model with another submit mode: a document's submit choosing over x-submitMode.
std::string_view actionType () const noexcept
 The action type the form submits.
std::string_view title () const noexcept
 The schema's top-level title, or the action type.
std::span< FieldSpec const > fields () const noexcept
 The top-level fields, in x-order.
std::span< FieldGroupSpec const > groups () const noexcept
 The layout groups: the declared x-layout groups, then an implicit group of the fields none names; without x-layout, one implicit group of every field.
std::span< RuleExpr const > rules () const noexcept
 The parsed x-rules, in declaration order.
SubmitMode submitMode () const noexcept
 When the form submits.
FieldSpec const * find (std::string_view name) const noexcept
 A top-level field by wire name.

Static Public Member Functions

static std::expected< FormModel, SchemaError > fromSchema (std::string_view actionType, std::string_view schemaJson, FieldOverlays const &overlays={})
 Reads a schema document, with the overlays a document or an application states for its fields.
template<class A>
static FormModel forAction ()
 The model of a registered action's own form: fromSchema over ActionTraits<A>::typeId() and schemaJson<A>().

Detailed Description

The immutable runtime model of one action's form.

Built from schema JSON by fromSchema; forAction<A>() (which the typed facade Form<A> uses) reads schemaJson<A>() through the same reader, so a typed and a runtime form of one action are the same model.

Definition at line 785 of file field_model.hpp.

Member Function Documentation

◆ fromSchema()

std::expected< FormModel, SchemaError > morph::forms::FormModel::fromSchema ( std::string_view actionType,
std::string_view schemaJson,
FieldOverlays const & overlays = {} )
inlinestaticnodiscard

Reads a schema document, with the overlays a document or an application states for its fields.

omit, hidden, label, widget and blankAs are applied to the schema before it is read, so a widget overlay chooses the kind exactly as the schema's own x-widget would; unit and decimals are applied to the read field. An overlay naming a field the schema does not have is a SchemaError, as is a unit that is not one of a Quantity's units.

Parameters
actionTypeThe action type the form submits (the registered type id).
schemaJsonThe schema, in the vocabulary schemaJson<A>() emits.
overlaysThe overlays of top-level fields, by wire name.
Returns
The model, or the error naming where the document is malformed.

Definition at line 798 of file field_model.hpp.

◆ withSubmitMode()

FormModel morph::forms::FormModel::withSubmitMode ( SubmitMode mode) const
inlinenodiscard

The same model with another submit mode: a document's submit choosing over x-submitMode.

Parameters
modeThe mode.
Returns
The model.

Definition at line 858 of file field_model.hpp.

◆ forAction()

template<class A>
FormModel morph::forms::FormModel::forAction ( )
staticnodiscard

The model of a registered action's own form: fromSchema over ActionTraits<A>::typeId() and schemaJson<A>().

Declared here and defined in forms/engine/typed_form.hpp, the one engine header that includes the schema emitters; include that header to call it. The schema is compiled from A, so a reader error is a defect in the emitter or the engine, never bad input: it throws rather than returning an expected every caller would have to unwrap.

Template Parameters
AThe action type (registered with BRIDGE_REGISTER_ACTION or declared with BRIDGE_DECLARE_ACTION).
Returns
The model.
Exceptions
std::logic_errornaming the action id and the error's path and message when the engine cannot read the action's schema.

Definition at line 33 of file typed_form.hpp.

◆ actionType()

std::string_view morph::forms::FormModel::actionType ( ) const
inlinenodiscardnoexcept

The action type the form submits.

Returns
The type id passed to fromSchema.

Definition at line 881 of file field_model.hpp.

◆ title()

std::string_view morph::forms::FormModel::title ( ) const
inlinenodiscardnoexcept

The schema's top-level title, or the action type.

Returns
The title.

Definition at line 885 of file field_model.hpp.

◆ fields()

std::span< FieldSpec const > morph::forms::FormModel::fields ( ) const
inlinenodiscardnoexcept

The top-level fields, in x-order.

Returns
The fields.

Definition at line 889 of file field_model.hpp.

◆ groups()

std::span< FieldGroupSpec const > morph::forms::FormModel::groups ( ) const
inlinenodiscardnoexcept

The layout groups: the declared x-layout groups, then an implicit group of the fields none names; without x-layout, one implicit group of every field.

Returns
The groups.

Definition at line 894 of file field_model.hpp.

◆ rules()

std::span< RuleExpr const > morph::forms::FormModel::rules ( ) const
inlinenodiscardnoexcept

The parsed x-rules, in declaration order.

Returns
The rules.

Definition at line 898 of file field_model.hpp.

◆ submitMode()

SubmitMode morph::forms::FormModel::submitMode ( ) const
inlinenodiscardnoexcept

When the form submits.

Returns
Explicit for x-submitMode: explicit, else Automatic.

Definition at line 902 of file field_model.hpp.

◆ find()

FieldSpec const * morph::forms::FormModel::find ( std::string_view name) const
inlinenodiscardnoexcept

A top-level field by wire name.

Parameters
nameThe wire name.
Returns
The field, or null.

Definition at line 907 of file field_model.hpp.


The documentation for this class was generated from the following files: