Class: Ruby2html::RailsComponents::FormWith
- Inherits:
-
BaseComponent
show all
- Includes:
- ActionView::Helpers::FormHelper
- Defined in:
- lib/gem/ruby2html/rails_components/form_with.rb
Instance Method Summary
collapse
#initialize
Instance Method Details
#file_field(method, options = {}) ⇒ Object
46
47
48
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 46
def file_field(method, options = {})
@render.input(**options.merge(type: 'file', name: field_name(method), id: field_id(method)))
end
|
#hidden_field(method, options = {}) ⇒ Object
38
39
40
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 38
def hidden_field(method, options = {})
@render.input(**options.merge(type: 'hidden', name: field_name(method), id: field_id(method), value: object_value_for(method)))
end
|
#label(method, text = nil, options = {}) ⇒ Object
28
29
30
31
32
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 28
def label(method, text = nil, options = {})
@render.label(**options.merge(for: field_id(method))) do
text || method.to_s.humanize
end
end
|
#password_field(method, options = {}) ⇒ Object
42
43
44
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 42
def password_field(method, options = {})
@render.input(**options.merge(type: 'password', name: field_name(method), id: field_id(method)))
end
|
#render(&block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 7
def render(&block)
model = @options[:model]
scope = @options[:scope]
url = @options[:url]
method = @options[:method]
local = @options[:local]
form_options = @options.except(:model, :scope, :url, :method, :local)
form_options[:action] = determine_url(model, url)
form_options[:method] = determine_method(model, method)
form_options['data-remote'] = 'true' unless local
@model = model
@scope = determine_scope(model, scope)
@render.form(**form_options) do
authenticity_token_tag
utf8_enforcer_tag
block.call(self)
end
end
|
#submit(value = nil, options = {}) ⇒ Object
50
51
52
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 50
def submit(value = nil, options = {})
@render.input(**options.merge(type: 'submit', value: value || submit_default_value))
end
|
#text_field(method, options = {}) ⇒ Object
34
35
36
|
# File 'lib/gem/ruby2html/rails_components/form_with.rb', line 34
def text_field(method, options = {})
@render.input(**options.merge(type: 'text', name: field_name(method), id: field_id(method), value: object_value_for(method)))
end
|