Module: LesliView::Forms::Inputs

Included in:
Builder
Defined in:
lib/lesli_view/forms/inputs.rb

Instance Method Summary collapse

Instance Method Details

#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



8
9
10
11
# File 'lib/lesli_view/forms/inputs.rb', line 8

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
    value = @object.send(method)
    super(method, options, checked_value, unchecked_value)
end

#email_field(method, options = {}) ⇒ Object



28
29
30
31
# File 'lib/lesli_view/forms/inputs.rb', line 28

def email_field(method, options = {})
    value = @object.send(method)
    super(method, options.merge(value: value, class: 'input'))
end

#label(method, text = nil, options = {}) ⇒ Object



4
5
6
# File 'lib/lesli_view/forms/inputs.rb', line 4

def label(method, text = nil, options = {})
    super(method, text, options.merge(class: 'label'))
end

#password_field(method, options = {}) ⇒ Object



33
34
35
36
# File 'lib/lesli_view/forms/inputs.rb', line 33

def password_field(method, options = {})
    value = @object.send(method)
    super(method, options.merge(value: value, class: 'input'))
end

#submit(value = nil, options = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/lesli_view/forms/inputs.rb', line 38

def submit(value=nil, options = {})
    # Extract and merge classes properly
    default_classes = "button is-primary"
    custom_classes = options[:class] || ""
    merged_classes = "#{default_classes} #{custom_classes}".strip
    super(value, options.merge(class: merged_classes))
end

#text_editor(method, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/lesli_view/forms/inputs.rb', line 18

def text_editor(method, options = {})
    input_id = "#{object_name}_#{method}"
    editor_id = "#{input_id}_editor"
    
    hidden_field(method) +
    @template.("trix-toolbar", "", id: editor_id) +
    @template.("trix-editor", "", toolbar: editor_id, input: input_id)
end

#text_field(method, options = {}) ⇒ Object



13
14
15
16
# File 'lib/lesli_view/forms/inputs.rb', line 13

def text_field(method, options = {})
    value = @object.send(method) if @object
    super(method, options.merge(value: value, class: 'input'))
end