Class: Protoform::Rails::Form

Inherits:
Component
  • Object
show all
Includes:
Phlex::Rails::Helpers::FormAuthenticityToken, Phlex::Rails::Helpers::URLFor
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_templateObject



52
53
54
55
56
57
58
59
# File 'lib/protoform/rails/form.rb', line 52

def around_template(&)
  form_tag do
    authenticity_token_field if authenticity_token?
    _method_field if method_field?

    super
  end
end

#assignObject



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

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

#collectionObject



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

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

#fieldObject



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

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

#form_tagObject



61
62
63
64
65
66
67
68
# File 'lib/protoform/rails/form.rb', line 61

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

#keyObject



83
84
85
# File 'lib/protoform/rails/form.rb', line 83

def key
  @model.model_name.param_key
end

#namespaceObject



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

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

#serializeObject



48
49
50
# File 'lib/protoform/rails/form.rb', line 48

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

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



74
75
76
77
78
79
80
81
# File 'lib/protoform/rails/form.rb', line 74

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

#view_templateObject



70
71
72
# File 'lib/protoform/rails/form.rb', line 70

def view_template(&)
  yield_content(&)
end