Class: Protoform::Rails::Form

Inherits:
Component
  • Object
show all
Defined in:
lib/protoform/rails/form.rb,
lib/protoform/rails/form/field.rb

Overview

A Protos::Component class that accepts a model and sets a ‘Protoform::Namespace` with the `Object#model_name` as the key and maps the object to form fields and namespaces.

The ‘Form::Field` is a class that’s meant to be extended so you can customize the ‘Form` inputs to your applications needs. Defaults for the `input`, `button`, `label`, and `textarea` tags are provided.

The ‘Form` component also handles Rails authenticity tokens via the `authenticity_toklen_field` method and the HTTP verb via the `_method_field`.

Direct Known Subclasses

ApplicationForm

Defined Under Namespace

Classes: Field

Instance Method Summary collapse

Instance Method Details

#around_template(&block) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/protoform/rails/form.rb', line 48

def around_template(&block)
  form_tag do
    authenticity_token_field if @authenticity_token

    _method_field
    super
  end
end

#assignObject



40
41
42
# File 'lib/protoform/rails/form.rb', line 40

def assign(...)
  @namespace.assign(...)
end

#collectionObject



32
33
34
# File 'lib/protoform/rails/form.rb', line 32

def collection(...)
  @namespace.collection(...)
end

#fieldObject



28
29
30
# File 'lib/protoform/rails/form.rb', line 28

def field(...)
  @namespace.field(...)
end

#form_tag(&block) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/protoform/rails/form.rb', line 57

def form_tag(&block)
  form(
    action: form_action,
    method: form_method,
    **attrs,
    &block
  )
end

#keyObject



80
81
82
# File 'lib/protoform/rails/form.rb', line 80

def key
  @model.model_name.param_key
end

#namespaceObject



36
37
38
# File 'lib/protoform/rails/form.rb', line 36

def namespace(...)
  @namespace.namespace(...)
end

#serializeObject



44
45
46
# File 'lib/protoform/rails/form.rb', line 44

def serialize(...)
  @namespace.serialize(...)
end

#submit(value = submit_value, **attributes) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/protoform/rails/form.rb', line 70

def submit(value = submit_value, **attributes)
  input(
    **attributes.merge(
      name: "commit",
      type: "submit",
      value:
    )
  )
end

#view_template(&block) ⇒ Object



66
67
68
# File 'lib/protoform/rails/form.rb', line 66

def view_template(&block)
  yield_content(&block)
end