Class: Forms::Submit

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/forms/submit.rb

Overview

Submit button, delegating markup and variants to DaisyUI::Button. Defaults its label from the model's persistence state (Create/Update ) via i18n, or takes explicit text.

Submit()                 # "Create User" / "Update User"
Submit(:primary, :lg)    # default text, modifiers
Submit("Save")           # custom text
Submit("Save", :primary) # custom text + modifiers

Instance Method Summary collapse

Constructor Details

#initialize(*args, model: nil, disabled: false, **attributes) ⇒ Submit

Returns a new instance of Submit.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/forms/submit.rb', line 13

def initialize(*args, model: nil, disabled: false, **attributes)
  if args.first.is_a?(String) || args.first.nil?
    @text = args.first
    @modifiers = args.drop(1)
  else
    @text = nil
    @modifiers = args
  end
  @model = model
  @disabled = disabled
  @attributes = attributes
  super()
end

Instance Method Details

#view_template(&block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/forms/submit.rb', line 27

def view_template(&block)
  attrs = { type: "submit", **@attributes }
  attrs[:disabled] = true if @disabled
  render DaisyUI::Button.new(*@modifiers, **attrs) do
    block ? yield : button_text
  end
end