TextInputBuilder

Struct TextInputBuilder 

Source
pub struct TextInputBuilder<'a, A> { /* private fields */ }
Expand description

Build a Text Input element

Allows you to construct a text input safely, with compile-time checks on required setter methods.

§Required Methods

TextInputBuilder::build() is only available if these methods have been called:

  • action_id

§Examples

use slack_blocks::{blocks::{Block, Input},
                   elems::TextInput};

let text_input = TextInput::builder().action_id("plate_num")
                                     .placeholder("ABC1234")
                                     .length(1..=7)
                                     .build();

let block: Block = Input::builder().label("enter custom license plate")
                                   .element(text_input)
                                   .dispatch_actions(true)
                                   .build()
                                   .into();

Implementations§

Source§

impl<'a, A> TextInputBuilder<'a, A>

Source

pub fn new() -> Self

Construct a new text input builder of empty state

Source

pub fn action_id( self, action_id: impl Into<Cow<'a, str>>, ) -> TextInputBuilder<'a, Set<action_id>>

Set action_id (Required)

An identifier for the input value when the parent modal is submitted.

You can use this when you receive a view_submission payload to identify the value of the input element 🔗.

Should be unique among all other action_ids in the containing block.

Maximum length for this field is 255 characters.

Source

pub fn action_trigger(self, trigger: ActionTrigger) -> Self

Add a new event trigger (Optional)

In messages, in order to receive events you must invoke this method and set dispatch_action to true on the containing Input block.

In modals and other contexts, the value of this element will be included with the submission of the form.

By invoking this with ActionTrigger::OnCharacterEntered, ActionTrigger::OnEnterPressed, or both, you can configure the input element to send additional events when these triggers are fired by the client.

For more info on these events, see block_actions interaction payload 🔗.

§Examples
use slack_blocks::{blocks::{Block, Input},
                   elems::{text_input::ActionTrigger::OnCharacterEntered,
                           TextInput}};

let text_input = TextInput::builder().action_id("plate_num")
                                     .placeholder("ABC1234")
                                     .length(1..=7)
                                     .action_trigger(OnCharacterEntered)
                                     .build();

let block: Block = Input::builder().label("enter custom license plate")
                                   .element(text_input)
                                   .dispatch_actions(true)
                                   .build()
                                   .into();
Source

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

Set placeholder (Optional)

A plain_text only text object 🔗 that defines the placeholder text shown in the plain-text input.

Maximum length for the text in this field is 150 characters.

Source

pub fn initial_value(self, init: impl Into<Cow<'a, str>>) -> Self

Set initial value (Optional)

The initial value in the plain-text input when it is loaded.

Source

pub fn multiline(self, multiline: bool) -> Self

Set multiline (Optional)

Indicates that the input will be a larger textarea, rather than a single line.

Default is false.

Source

pub fn min_length(self, min: u32) -> Self

Set min_length (Optional)

The minimum length of input that the user must provide.

If the user provides less, they will receive an error.

Maximum value is 3000.

Source

pub fn max_length(self, max: u32) -> Self

Set max_length (Optional)

The maximum length of input that the user can provide.

If the user provides more, they will receive an error.

Source

pub fn length(self, rng: impl RangeBounds<u32>) -> Self

Set min_length and/or max_length with a rust range literal (Optional)

use slack_blocks::elems::TextInput;

TextInput::builder().action_id("vanity_plate")
                    .placeholder("enter your desired custom license plate")
                    .length(1..=7);
use slack_blocks::elems::TextInput;

TextInput::builder().action_id("first_name")
                    .placeholder("enter your first name")
                    .length(2..);
use slack_blocks::elems::TextInput;

TextInput::builder()
          .action_id("does nothing")
          .placeholder("This is the same as not calling length at all!")
          .length(..);
Source§

impl<'a> TextInputBuilder<'a, Set<action_id>>

Source

pub fn build(self) -> TextInput<'a>

All done building, now give me a darn text input!

no method name 'build' found for struct 'text_input::build::TextInputBuilder<...>'? Make sure all required setter methods have been called. See docs for TextInputBuilder.

use slack_blocks::elems::TextInput;

let sel = TextInput::builder().build(); // Won't compile!
use slack_blocks::elems::TextInput;

let sel = TextInput::builder().action_id("bar").build();

Trait Implementations§

Source§

impl<'a, A: Debug> Debug for TextInputBuilder<'a, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, A> Freeze for TextInputBuilder<'a, A>

§

impl<'a, A> RefUnwindSafe for TextInputBuilder<'a, A>
where A: RefUnwindSafe,

§

impl<'a, A> Send for TextInputBuilder<'a, A>
where A: Send,

§

impl<'a, A> Sync for TextInputBuilder<'a, A>
where A: Sync,

§

impl<'a, A> Unpin for TextInputBuilder<'a, A>
where A: Unpin,

§

impl<'a, A> UnwindSafe for TextInputBuilder<'a, A>
where A: UnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoChild for T

Source§

fn into_child(self) -> Self

Available on crate feature blox only.
Identity function
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> ErasedDestructor for T
where T: 'static,