Skip to main content

FieldType

Trait FieldType 

Source
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,
    ) -> Result<ResolvedOptions, OptionsError> { ... }
    fn intrinsic_rules(&self, _opts: &ResolvedOptions) -> Vec<Rule> { ... }
    fn to_attr(
        &self,
        raw: Option<&str>,
        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> { ... }
}
Expand description

A field type: behaviour registered once per string key.

Required Methods§

Source

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).

Source

fn view_model(&self, cx: &FieldCx<'_>) -> FieldVm

Builds the serialisable presentation payload. Pure, no IO.

Source

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§

Source

fn resolve_options(&self, _raw: &Value) -> Result<ResolvedOptions, OptionsError>

Types the descriptor’s raw options blob once at boot. A failure aborts boot naming the resource + field. Default: no options.

Source

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).

Source

fn to_attr( &self, raw: Option<&str>, 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.

Source

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.

Source

fn chrome(&self) -> Chrome

Whether the framework wraps this field in standard chrome.

Source

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".

Implementors§