Class: Slack::BlockKit::Element::NumberInput

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

Overview

Works with block types: Input

Number input elements are supported in the following app surfaces: Modals

This input elements accepts both whole and decimal numbers. For example, 0.25, 5.5, and -10 are all valid input values. Decimal numbers are only allowed when is_decimal_allowed is equal to true.

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

Constant Summary collapse

TYPE =
'number_input'

Instance Method Summary collapse

Constructor Details

#initialize(action_id:, is_decimal_allowed:, placeholder: nil, initial_value: nil, min_value: nil, max_value: nil, focus_on_load: nil) ⇒ NumberInput

Returns a new instance of NumberInput.



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

def initialize(
  action_id:,
  is_decimal_allowed:,
  placeholder: nil,
  initial_value: nil,
  min_value: nil,
  max_value: nil,
  focus_on_load: nil
)
  @placeholder = placeholder && Composition::PlainText.new(text: placeholder)
  @initial_value = initial_value
  @action_id = action_id
  @is_decimal_allowed = is_decimal_allowed
  @focus_on_load = focus_on_load
  @dispatch_action_config = nil
  @min_value = min_value
  @max_value = max_value
end

Instance Method Details

#as_jsonObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/slack/block_kit/element/number_input.rb', line 46

def as_json(*)
  {
    type: TYPE,
    action_id: @action_id,
    is_decimal_allowed: @is_decimal_allowed,
    placeholder: @placeholder&.as_json,
    initial_value: @initial_value,
    min_value: @min_value,
    max_value: @max_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



38
39
40
41
42
43
44
# File 'lib/slack/block_kit/element/number_input.rb', line 38

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

  yield(@dispatch_action_config) if block_given?

  self
end