Class: Slack::BlockKit::Element::PlainTextInput

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/block_kit/element/plain_text_input.rb

Overview

A plain-text input, similar to the HTML <input> tag, creates a field where a user can enter freeform data. It can appear as a single-line field or a larger textarea using the multiline flag.

Plain-text input elements are currently only available in modals

api.slack.com/reference/block-kit/block-elements#input

Constant Summary collapse

TYPE =
'plain_text_input'

Instance Method Summary collapse

Constructor Details

#initialize(action_id:, placeholder: nil, emoji: nil, initial_value: nil, multiline: nil, min_length: nil, max_length: nil, focus_on_load: nil) ⇒ PlainTextInput

Returns a new instance of PlainTextInput.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/slack/block_kit/element/plain_text_input.rb', line 16

def initialize(
  action_id:,
  placeholder: nil,
  emoji: nil,
  initial_value: nil,
  multiline: nil,
  min_length: nil,
  max_length: nil,
  focus_on_load: nil
)
  @placeholder = placeholder && Composition::PlainText.new(text: placeholder, emoji: emoji)
  @initial_value = initial_value
  @action_id = action_id
  @multiline = multiline
  @min_length = min_length
  @max_length = max_length
  @focus_on_load = focus_on_load
  @dispatch_action_config = nil
end

Instance Method Details

#as_jsonObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/slack/block_kit/element/plain_text_input.rb', line 44

def as_json(*)
  {
    type: TYPE,
    action_id: @action_id,
    placeholder: @placeholder&.as_json,
    multiline: @multiline,
    min_length: @min_length,
    max_length: @max_length,
    initial_value: @initial_value,
    focus_on_load: @focus_on_load,
    dispatch_action_config: @dispatch_action_config&.as_json
  }.compact
end

#dispatch_action_config(triggers: nil) {|@dispatch_action_config| ... } ⇒ Object



36
37
38
39
40
41
42
# File 'lib/slack/block_kit/element/plain_text_input.rb', line 36

def dispatch_action_config(triggers: nil)
  @dispatch_action_config = Composition::DispatchActionConfiguration.new(triggers: triggers)

  yield(@dispatch_action_config) if block_given?

  self
end