pub trait FieldType:
Send
+ Sync
+ 'static {
// Required methods
fn view_key(&self) -> &'static str;
fn view_model(&self, cx: &FieldCx<'_>) -> FieldVm;
fn render_default(&self, vm: &FieldVm) -> Markup;
// Provided methods
fn resolve_options(
&self,
_raw: &Value,
_types: &FieldRegistry,
) -> Result<ResolvedOptions, OptionsError> { ... }
fn intrinsic_rules(&self, _opts: &ResolvedOptions) -> Vec<Rule> { ... }
fn to_attr(
&self,
field: &SubmittedField<'_>,
opts: &ResolvedOptions,
mode: Mode,
) -> Result<Option<AttrValue>, String> { ... }
fn to_control(&self, stored: Option<&str>, opts: &ResolvedOptions) -> String { ... }
fn chrome(&self) -> Chrome { ... }
fn assets(&self, _opts: &ResolvedOptions) -> Vec<&'static str> { ... }
}Required Methods§
Sourcefn view_key(&self) -> &'static str
fn view_key(&self) -> &'static str
The stable key for override resolution and default-template selection
(bare like text for core; dotted vendor.name for plugins).
Sourcefn view_model(&self, cx: &FieldCx<'_>) -> FieldVm
fn view_model(&self, cx: &FieldCx<'_>) -> FieldVm
Builds the serialisable presentation payload. Pure, no IO.
Sourcefn render_default(&self, vm: &FieldVm) -> Markup
fn render_default(&self, vm: &FieldVm) -> Markup
The built-in presenter over the view-model (an Askama partial). Not called when an override wins.
Provided Methods§
Sourcefn resolve_options(
&self,
_raw: &Value,
_types: &FieldRegistry,
) -> Result<ResolvedOptions, OptionsError>
fn resolve_options( &self, _raw: &Value, _types: &FieldRegistry, ) -> Result<ResolvedOptions, OptionsError>
Types the descriptor’s raw options blob once at boot. A failure aborts boot naming the resource + field. Default: no options.
types is the field registry, for a composite field (a repeater) that
holds fields of its own and has to resolve their types and options here,
while the registry is in hand.
Sourcefn intrinsic_rules(&self, _opts: &ResolvedOptions) -> Vec<Rule>
fn intrinsic_rules(&self, _opts: &ResolvedOptions) -> Vec<Rule>
Rules this type always contributes, merged before the descriptor’s own
(e.g. the text field’s email input contributes Rule::Email).
Sourcefn to_attr(
&self,
field: &SubmittedField<'_>,
opts: &ResolvedOptions,
mode: Mode,
) -> Result<Option<AttrValue>, String>
fn to_attr( &self, field: &SubmittedField<'_>, opts: &ResolvedOptions, mode: Mode, ) -> Result<Option<AttrValue>, String>
How a submitted value becomes the attribute that gets stored.
raw is None when the submission omits the field entirely, which is
how an unchecked checkbox arrives. Returning None leaves the attribute
out of the write, so the column keeps whatever it held: that is how a
blank password on an edit means “unchanged” rather than “erase”.
Validation has already run, so a type that needs its input to parse
should guarantee that with an intrinsic_rules
entry and treat the value here as sound. The error is for a genuine
failure (hashing), not a bad value, and surfaces as a failed save.
Default: the submitted text, unchanged.
Sourcefn to_control(&self, stored: Option<&str>, opts: &ResolvedOptions) -> String
fn to_control(&self, stored: Option<&str>, opts: &ResolvedOptions) -> String
How a stored value is presented back in the control on an edit.
The counterpart of to_attr: storage and
presentation differ whenever a type stores something other than the text
the browser sent, and a type that never shows its value (a password)
returns the empty string here.
Default: the stored text, unchanged.
Sourcefn assets(&self, _opts: &ResolvedOptions) -> Vec<&'static str>
fn assets(&self, _opts: &ResolvedOptions) -> Vec<&'static str>
Asset-registry keys this type’s control needs on any page that renders it
(a heavy widget’s script/style). The page shell collects, dedupes, and
emits them; keys must exist in the asset registry. Default: none, so a
type whose widget ships in core laterite.js declares nothing.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".