morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
choice.hpp File Reference

Fields whose value is picked from a list served by another action. More...

#include <array>
#include <cstddef>
#include <glaze/glaze.hpp>
#include <optional>
#include <string_view>
#include <type_traits>
#include "../attributes.hpp"
#include "../detail/fixed_string.hpp"
#include "detail/schema_name.hpp"

Go to the source code of this file.

Classes

struct  morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >
 An optionally-empty value selected from options served by another action. More...

Typedefs

template<std::size_t N>
using morph::forms::FixedString = ::morph::detail::FixedString<N>
 A structural, NTTP-capable compile-time string (for naming the options action and its value/label result fields in the type).

Variables

template<typename T>
constexpr bool morph::forms::isChoice = detail::IsChoice<std::remove_cvref_t<T>>::value
 true when T (cvref-stripped) is a morph::forms::Choice.

Detailed Description

Fields whose value is picked from a list served by another action.

A morph::forms::Choice<T, "ListPayees"> member declares, in the type: this field is not free input — its options are the result of executing the named action. Renderers turn it into a combo box: they execute the options action (over the same wire the form actions use), read the result rows, and offer labelField as the display text while submitting valueField as the payload.

struct SampleInfo { std::int64_t id = 0; std::string name; };
struct SampleList { std::vector<SampleInfo> samples; };
struct ListSamples {}; // registered like any other action (a pure query)
struct RecordMeasurement {
morph::forms::Choice<std::int64_t, "ListSamples"> sampleId; // combo box
...
};

In the generated schema the declaration surfaces as x-optionsAction / x-optionValue / x-optionLabel on the property (added by morph::forms::schemaJson), so a client knows which action to call and which result fields to use without hardcoding anything.

A Choice can also declare a DependsOn pack naming sibling fields whose current values parameterise the options action — a cascading picklist (e.g. the list of cities depends on the selected country). The options action then receives {name: value, ...} instead of an empty body, and the schema additionally carries x-optionsDependsOn. See optionsDependsOn() below; a Choice with no DependsOn is unaffected.

On the wire a Choice is its nullable underlying value (T); the options metadata never travels with payloads. Like Quantity and Timestamp, the blank state ("nothing selected") lives inside, and a non-optional Choice member is required by the morph::forms rules.

Definition in file choice.hpp.

Typedef Documentation

◆ FixedString

template<std::size_t N>
using morph::forms::FixedString = ::morph::detail::FixedString<N>

A structural, NTTP-capable compile-time string (for naming the options action and its value/label result fields in the type).

An alias for the shared morph::detail::FixedString — the same underlying type the units layer's NamedQuantity uses — so there is one definition, not two look-alikes. Kept as a public morph::forms:: name for source compatibility.

Template Parameters
NStorage size including the terminating null.

Definition at line 65 of file choice.hpp.

Variable Documentation

◆ isChoice

template<typename T>
bool morph::forms::isChoice = detail::IsChoice<std::remove_cvref_t<T>>::value
inlineconstexpr

true when T (cvref-stripped) is a morph::forms::Choice.

Definition at line 153 of file choice.hpp.