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>
impl<'a, A> TextInputBuilder<'a, A>
Sourcepub fn action_id(
self,
action_id: impl Into<Cow<'a, str>>,
) -> TextInputBuilder<'a, Set<action_id>>
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.
Sourcepub fn action_trigger(self, trigger: ActionTrigger) -> Self
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();Sourcepub fn placeholder(self, placeholder: impl Into<Plain>) -> Self
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.
Sourcepub fn initial_value(self, init: impl Into<Cow<'a, str>>) -> Self
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.
Sourcepub fn multiline(self, multiline: bool) -> Self
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.
Sourcepub fn min_length(self, min: u32) -> Self
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.
Sourcepub fn max_length(self, max: u32) -> Self
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.
Sourcepub fn length(self, rng: impl RangeBounds<u32>) -> Self
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>>
impl<'a> TextInputBuilder<'a, Set<action_id>>
Sourcepub fn build(self) -> TextInput<'a>
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 forTextInputBuilder.
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();