Struct slack_messaging::blocks::elements::UrlInput
source · pub struct UrlInput { /* private fields */ }Expand description
URL input element representation.
Example
use slack_messaging::blocks::elements::UrlInput;
use serde_json::json;
let url = UrlInput::new()
.set_action_id("url_input_action")
.placeholder("Enter url");
let expected = json!({
"type": "url_text_input",
"action_id": "url_input_action",
"placeholder": {
"type": "plain_text",
"text": "Enter url",
"emoji": true
}
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);Implementations§
source§impl UrlInput
impl UrlInput
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a URL input element with empty values.
use slack_messaging::blocks::elements::UrlInput;
use serde_json::json;
let url = UrlInput::new();
let expected = json!({
"type": "url_text_input",
"action_id": ""
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);sourcepub fn set_action_id<T: Into<String>>(self, action_id: T) -> Self
pub fn set_action_id<T: Into<String>>(self, action_id: T) -> Self
Sets action_id field.
use slack_messaging::blocks::elements::UrlInput;
use serde_json::json;
let url = UrlInput::new().set_action_id("url_input_action");
let expected = json!({
"type": "url_text_input",
"action_id": "url_input_action"
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);sourcepub fn set_initial_value<T: Into<String>>(self, value: T) -> Self
pub fn set_initial_value<T: Into<String>>(self, value: T) -> Self
Sets initial_value field.
use slack_messaging::blocks::elements::UrlInput;
use serde_json::json;
let url = UrlInput::new().set_initial_value("https://google.com");
let expected = json!({
"type": "url_text_input",
"action_id": "",
"initial_value": "https://google.com"
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);sourcepub fn set_dispatch_action_config(
self,
config: DispatchActionConfiguration
) -> Self
pub fn set_dispatch_action_config( self, config: DispatchActionConfiguration ) -> Self
Sets dispatch_action_config field with DispatchActionConfiguration object.
use slack_messaging::blocks::elements::{UrlInput, DispatchActionConfiguration,
TriggerAction};
use serde_json::json;
let url = UrlInput::new()
.set_dispatch_action_config(
DispatchActionConfiguration::new()
.push_trigger_action(TriggerAction::OnEnterPressed)
.push_trigger_action(TriggerAction::OnCharacterEntered)
);
let expected = json!({
"type": "url_text_input",
"action_id": "",
"dispatch_action_config": {
"trigger_actions_on": ["on_enter_pressed", "on_character_entered"]
}
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);sourcepub fn set_focus_on_load(self, focus_on_load: bool) -> Self
pub fn set_focus_on_load(self, focus_on_load: bool) -> Self
Sets focus_on_load field.
use slack_messaging::blocks::elements::UrlInput;
use serde_json::json;
let url = UrlInput::new().set_focus_on_load(true);
let expected = json!({
"type": "url_text_input",
"action_id": "",
"focus_on_load": true
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);sourcepub fn set_placeholder(self, placeholder: Text) -> Self
pub fn set_placeholder(self, placeholder: Text) -> Self
Sets placeholder field.
use slack_messaging::blocks::elements::{UrlInput, Text};
use serde_json::json;
let url = UrlInput::new()
.set_placeholder(Text::plain("Enter url"));
let expected = json!({
"type": "url_text_input",
"action_id": "",
"placeholder": {
"type": "plain_text",
"text": "Enter url",
"emoji": true
}
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);sourcepub fn placeholder<T: Into<String>>(self, placeholder: T) -> Self
pub fn placeholder<T: Into<String>>(self, placeholder: T) -> Self
Sets placeholder field from string. This is a shorthand for set_placeholder method.
use slack_messaging::blocks::elements::UrlInput;
use serde_json::json;
let url = UrlInput::new().placeholder("Enter url");
let expected = json!({
"type": "url_text_input",
"action_id": "",
"placeholder": {
"type": "plain_text",
"text": "Enter url",
"emoji": true
}
});
let url_json = serde_json::to_value(url).unwrap();
assert_eq!(url_json, expected);