|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
The reactive state of one form: a controller over a FormModel. More...
#include <form_session.hpp>
Public Member Functions | |
| FormSession (reactive::Runtime &runtime, FormModel model, Submitter submit, ChoiceFetcher choices, FormSessionOptions options={}) | |
| FormSession (FormSession const &)=delete | |
| FormSession & | operator= (FormSession const &)=delete |
| FormSession (FormSession &&)=delete | |
| FormSession & | operator= (FormSession &&)=delete |
| FormModel const & | model () const noexcept |
| The form model. | |
| reactive::Runtime & | runtime () const noexcept |
| The runtime. | |
| SubmitMode | submitMode () const noexcept |
| When the form submits. | |
| FormSessionOptions const & | options () const noexcept |
| The session options. | |
| std::span< std::unique_ptr< FieldState > const > | fields () const noexcept |
| The top-level fields, in x-order. | |
| FieldState & | field (std::string_view path) const |
| A field by path: name, parent.member, or rows[i].member (a row by position). | |
| bool | ready () const |
| Whether the form can submit. Tracked. | |
| std::optional< std::string > | body () const |
| The body the form would submit. Tracked. | |
| void | submit () |
| Submits the current body; does nothing while not ready, or while a submission is in flight (the submission is Exclusive). The explicit-mode trigger; in automatic mode it forces a resubmission of an unchanged body. | |
| void | prefill (std::string_view bodyJson) |
| Loads a stored payload for editing. Every field is replaced (an absent member starts blank), every unit returns to the canonical one, and nothing is submitted. Text that is not a JSON object changes nothing. | |
| void | refill (std::string_view bodyJson) |
| Loads a stored payload like prefill, except that a top-level field the user changed since the form was last loaded keeps what they entered: a later value of the record being edited, such as its first value arriving after the user started typing, or a refetch, does not discard the edit. Nothing is submitted. Text that is not a JSON object changes nothing. | |
| void | assign (std::string_view path, std::string_view jsonValue) |
| Sets one field from a JSON value, programmatically (nothing is submitted). | |
| void | reset () |
| Blanks every field, programmatically (nothing is submitted). | |
| bool | pending () const |
| Whether a submission is in flight. Tracked. | |
| std::optional< std::string > const & | lastReply () const |
| The last successful reply. Tracked. | |
| std::exception_ptr | lastError () const |
| The last failure. Tracked. | |
| std::uint64_t | successCount () const |
| How many submissions have succeeded. Tracked; each success ticks it, so an observer sees every submission even when two replies are equal. | |
| std::uint64_t | submitAttempts () const |
| How many submissions have been sent, automatic and explicit. Tracked; a submission the Exclusive mutation refused while another was in flight does not count. | |
| reactive::Signal< bool > & | groupCollapsed (std::size_t group) const |
| An accordion group's collapsed state. | |
| reactive::Signal< std::size_t > & | tabSelection (std::size_t group) const |
| A tab run's selected tab, keyed by the run's first group index. | |
| std::string | groupTitle (std::size_t group) const |
| A group's title, resolved through the translations (key <action>.group.<index>). | |
Static Public Member Functions | |
| static std::optional< std::size_t > | rowIndexOf (std::string_view digits) |
| A row position written in a path's brackets. | |
The reactive state of one form: a controller over a FormModel.
Non-copyable and non-movable: fields, bindings and in-flight replies point into it. Destroy a mounted view of it before the session.
Definition at line 777 of file form_session.hpp.
|
inline |
| runtime | The runtime. Borrowed: it must outlive the session. |
| model | The form model. |
| submit | Executes the form's action. Required. |
| choices | Fetches Choice options; may be empty when no field is a Choice. |
| options | Locale, translations, display zone, extra readiness gate. |
| std::invalid_argument | when submit is empty. |
Definition at line 785 of file form_session.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
The runtime.
Definition at line 835 of file form_session.hpp.
|
inlinenodiscardnoexcept |
When the form submits.
Definition at line 839 of file form_session.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
The top-level fields, in x-order.
Definition at line 847 of file form_session.hpp.
|
inlinestaticnodiscard |
A row position written in a path's brackets.
| digits | The text between the brackets. |
Definition at line 852 of file form_session.hpp.
|
inlinenodiscard |
A field by path: name, parent.member, or rows[i].member (a row by position).
| path | The path. |
| std::out_of_range | when no field has that path. |
Definition at line 866 of file form_session.hpp.
|
inlinenodiscard |
Whether the form can submit. Tracked.
Definition at line 916 of file form_session.hpp.
|
inlinenodiscard |
The body the form would submit. Tracked.
Definition at line 920 of file form_session.hpp.
|
inline |
Submits the current body; does nothing while not ready, or while a submission is in flight (the submission is Exclusive). The explicit-mode trigger; in automatic mode it forces a resubmission of an unchanged body.
Definition at line 925 of file form_session.hpp.
|
inline |
Loads a stored payload for editing. Every field is replaced (an absent member starts blank), every unit returns to the canonical one, and nothing is submitted. Text that is not a JSON object changes nothing.
| bodyJson | The payload. |
Definition at line 940 of file form_session.hpp.
|
inline |
Loads a stored payload like prefill, except that a top-level field the user changed since the form was last loaded keeps what they entered: a later value of the record being edited, such as its first value arriving after the user started typing, or a refetch, does not discard the edit. Nothing is submitted. Text that is not a JSON object changes nothing.
| bodyJson | The payload. |
Definition at line 959 of file form_session.hpp.
|
inline |
Sets one field from a JSON value, programmatically (nothing is submitted).
| path | The field's path (see field). |
| jsonValue | The value as JSON; text that is not JSON changes nothing. |
| std::out_of_range | when no field has that path. |
Definition at line 985 of file form_session.hpp.
|
inline |
Blanks every field, programmatically (nothing is submitted).
Definition at line 1006 of file form_session.hpp.
|
inlinenodiscard |
Whether a submission is in flight. Tracked.
Definition at line 1018 of file form_session.hpp.
|
inlinenodiscard |
The last successful reply. Tracked.
Definition at line 1022 of file form_session.hpp.
|
inlinenodiscard |
The last failure. Tracked.
Definition at line 1026 of file form_session.hpp.
|
inlinenodiscard |
How many submissions have succeeded. Tracked; each success ticks it, so an observer sees every submission even when two replies are equal.
Definition at line 1031 of file form_session.hpp.
|
inlinenodiscard |
How many submissions have been sent, automatic and explicit. Tracked; a submission the Exclusive mutation refused while another was in flight does not count.
Definition at line 1036 of file form_session.hpp.
|
inlinenodiscard |
An accordion group's collapsed state.
| group | Index into model().groups(). |
| std::out_of_range | for an index past the groups. |
Definition at line 1042 of file form_session.hpp.
|
inlinenodiscard |
A tab run's selected tab, keyed by the run's first group index.
| group | Index into model().groups() of the run's first tab group. |
| std::out_of_range | for an index past the groups. |
Definition at line 1048 of file form_session.hpp.
|
inlinenodiscard |
A group's title, resolved through the translations (key <action>.group.<index>).
| group | Index into model().groups(). |
| std::out_of_range | for an index past the groups. |
Definition at line 1054 of file form_session.hpp.