Skip to main content

RichTextField

Struct RichTextField 

Source
pub struct RichTextField<F = ()>(/* private fields */);
Expand description

A rich text field: Field::rich_text, or a record form’s text control made one with TextField::rich_text (F is the form).

  • The toolbar is the schema. .toolbar(..) takes groups of Tools, Tool::DEFAULT unless declared. Each tool names the elements it produces: Tool::Bold a <strong>, Tool::Link an <a href>, Tool::BulletList a <ul> of <li>. The editor registers only those, so a tool left off the toolbar cannot be typed and drops from a paste. The editor takes a link only to a URL the server keeps, and a code block’s language, which the editor records as a class, is not stored.
  • The server cleans what it reads. A submission keeps only the elements and attributes its field’s tools produce, before the record form parses it: a <script>, a style, an on… handler and a link to a scheme other than http, https or mailto never reach the column, and every link gets rel="noopener noreferrer nofollow". A document with no text reads as an empty submission, so the field’s blank answer applies, and the empty paragraphs the editor leaves at a document’s end are dropped.
  • Length rules count the text. .min_length(n) and .max_length(n) count the characters a reader sees, not the markup.
  • Without JavaScript the control is a <textarea> of the HTML, cleaned the same way on submit. The editor is TipTap, which the page loads only when it holds a rich text control.
  • A text column moving to rich text needs its values moved too. The field reads what the column stores as HTML, so a<b loses its <b, and each edit stores what it read. Rewrite each stored value through tablo::rich_text::from_text, which escapes it and wraps its paragraphs, before the field edits it.

Implementations§

Source§

impl<F: EditsRecords> RichTextField<F>

Source

pub fn hidden_on_create(self) -> Self

Renders nothing for the field on the create form. The create stores the field’s default, else its blank answer: a required field with neither cannot mount. A field hidden on both forms only ever stores that: set it in the record instead.

Source

pub fn hidden_on_edit(self) -> Self

Renders nothing for the field on the edit form, and keeps its stored value whatever an edit posts: the create form sets the value, and no edit changes it, as disabled_on_edit does without showing it.

Source§

impl<F> RichTextField<F>

Source

pub fn default(self, value: impl IntoFormValue) -> Self

Fills the create form’s control with value: any FormScalar or a &str in the form spelling, or, for a multiple choice, an array or Vec of them. On a disabled field it is the value a create stores. A schema refuses a default the control never posts: one a typed field does not parse, one not among a choice’s options, a list on a control posting one value, and one value on a multiple choice.

Field::choice(Post::fields().status())
    .options(["draft", "published"])
    .default("draft");
Field::text(Post::fields().views()).default(0_i64).disabled();
Field::choice_input("channels")
    .options(["email", "sms"])
    .multiple()
    .default(["email"]);
  • The control names its help text in aria-describedby, beside its error.
  • A disabled control renders disabled, so the browser posts nothing for it, and the panel drops a key posted anyway, with a file field’s carried upload. An edit keeps the stored value. A create stores the field’s default, else its blank answer: .disabled() on a field with neither refuses to mount, since no create could fill it.
  • .disabled_on_edit() leaves the create form’s control enabled: the create sets the value, and no edit changes it.
  • A condition watching a disabled field reads what the browser shows: its default on a create, its stored value on an edit, never what the submission posts.
  • A default seeds the create form and an action’s input form; an edit form shows the stored value. The blank answer is different: it is what an empty submission stores. Mounting refuses a default the control never posts: one a typed field does not parse, or not one of a choice’s options.
  • A repeater’s row controls take neither disabled nor default: mounting refuses both.
Source§

impl<F> RichTextField<F>

Source

pub fn label(self, label: impl Into<Text>) -> Self

Source

pub fn name(&self) -> &str

Source

pub fn visible_when( self, watched: &impl Watched<F>, values: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Shows the field only while watched posts one of values: an option’s value, or true for a checked toggle. A hidden field posts nothing, so an edit keeps its stored value and a create takes its blank answer; a field with no blank answer cannot be conditional. A field shows under one condition: a later call replaces an earlier one, so a field depending on two watched fields sits in a Section guarded by the other.

let kind = Field::choice(Customer::fields().kind()).options(["person", "company"]);
let vat = Field::text(Customer::fields().vat_number()).visible_when(&kind, ["company"]);
Schema::new((kind, vat));
  • The browser shows and hides the field as the watched one changes, with no request. A hidden field’s control is disabled, so the browser neither validates nor posts it. Without JavaScript, the fields start as the stored values show them and stay that way.
  • The panel reads a submission the same way and drops a hidden field’s posted key, and a file field’s carried upload: an edit keeps the stored value, and a create stores the blank answer. A conditional field therefore needs a blank answer, and mounting refuses one without.
  • Mounting also refuses a value the watched field never posts (a choice’s option or a toggle’s true and false are checked), and a condition watching a field that another condition hides while the guarded field still shows: place the guarded field inside the block that hides the watched one. A schema also refuses a condition watching a field it does not place, which only a page’s or an action’s schema can do: a resource’s form places every record-form field.
  • A toggle is followed through its checkbox. An app’s own checkbox Control posts the same value checked or not, so a condition cannot follow it.
  • A multiple choice’s key holds a list, which no condition value spells: mounting refuses a condition watching one.
Source

pub fn span(self, columns: u8) -> Self

Spans columns of the Grid holding the field, clamped to 1..12. While the grid stacks its children, or lays out fewer columns, the field spans them all. Outside a grid, the span does nothing.

Source

pub fn span_full(self) -> Self

Spans every column of the Grid holding the field.

Source§

impl<F> RichTextField<F>

Source

pub fn help(self, text: impl Into<Text>) -> Self

Renders text under the control, which the control names as its description.

Source

pub fn disabled(self) -> Self

Renders the control disabled on the create and edit forms. The server drops a value posted for it anyway, so an edit keeps the stored value and a create takes the field’s default, else its blank answer; a field with neither cannot be created, and its panel refuses to mount.

Source

pub fn disabled_on_edit(self) -> Self

Renders the control disabled on the edit form only: the create form sets the value, and no edit changes it.

Source

pub fn custom(self, control: impl Control + 'static) -> CustomField<F>

Renders the field with an app’s Control instead, as Field::custom does: how a record form’s control takes a custom input. The field keeps its key and label; the replaced control’s own modifiers, such as email, unique or options, are dropped with it.

Source§

impl<F> RichTextField<F>

Source

pub fn toolbar(self, groups: &[&[Tool]]) -> Self

The toolbar’s groups of Tools, in order, which also decide what the field keeps: a submission loses every element no tool here produces. Tool::DEFAULT by default.

use tablo_core::{Field, Tool};

Field::rich_text(Post::fields().summary()).toolbar(&[&[Tool::Bold, Tool::Italic, Tool::Link]]);
Source

pub fn placeholder(self, placeholder: impl Into<Text>) -> Self

The text the empty editor shows.

Source

pub fn min_length(self, chars: usize) -> Self

Refuse a value whose text holds fewer than chars characters. The markup does not count, and a value with no text is the field’s blank answer, which no rule refuses.

Source

pub fn max_length(self, chars: usize) -> Self

Refuse a value whose text holds more than chars characters. The markup does not count.

Trait Implementations§

Source§

impl<F> From<RichTextField<F>> for Field

Source§

fn from(builder: RichTextField<F>) -> Field

Converts to this type from the input type.
Source§

impl<F> IntoSchema<F> for RichTextField<F>

Auto Trait Implementations§

§

impl<F = ()> !RefUnwindSafe for RichTextField<F>

§

impl<F = ()> !UnwindSafe for RichTextField<F>

§

impl<F> Forget for RichTextField<F>

§

impl<F> Freeze for RichTextField<F>
where PhantomData<fn() -> F>: Freeze,

§

impl<F> Move for RichTextField<F>

§

impl<F> Send for RichTextField<F>
where PhantomData<fn() -> F>: Send,

§

impl<F> Sync for RichTextField<F>
where PhantomData<fn() -> F>: Sync,

§

impl<F> Unpin for RichTextField<F>
where PhantomData<fn() -> F>: Unpin,

§

impl<F> UnsafeUnpin for RichTextField<F>
where PhantomData<fn() -> F>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more