-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add form_with to unify form_tag/form_for. #26976
Changes from 1 commit
18a44be
c0df7c6
1e7e5cb
a4a5945
31a9608
3a55155
b714aa8
e3eb691
5a4052a
7d6fc1f
694c226
407d9f2
42f4fb2
15a805c
17429bb
30ebe5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Strips `_for` and requires models passed as a keyword argument.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -785,6 +785,17 @@ def fields_for(record_name, record_object = nil, options = {}, &block) | |
capture(builder, &block) | ||
end | ||
|
||
# TODO: Documentation | ||
def fields(scope = nil, model: nil, **options, &block) | ||
# TODO: Remove when ids and classes are no longer output by default. | ||
if model | ||
scope ||= model_name_from_record_or_class(model).param_key | ||
end | ||
|
||
builder = instantiate_builder(scope, model, options) | ||
capture(builder, &block) | ||
end | ||
|
||
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object | ||
# assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation | ||
# is found in the current I18n locale (through helpers.label.<modelname>.<attribute>) or you specify it explicitly. | ||
|
@@ -1314,7 +1325,7 @@ class FormBuilder | |
|
||
# The methods which wrap a form helper call. | ||
class_attribute :field_helpers | ||
self.field_helpers = [:fields_for, :label, :text_field, :password_field, | ||
self.field_helpers = [:fields_for, :fields, :label, :text_field, :password_field, | ||
:hidden_field, :file_field, :text_area, :check_box, | ||
:radio_button, :color_field, :search_field, | ||
:telephone_field, :phone_field, :date_field, | ||
|
@@ -1651,6 +1662,11 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block) | |
@template.fields_for(record_name, record_object, fields_options, &block) | ||
end | ||
|
||
# TODO: Documentation | ||
def fields(scope = nil, model: nil, **options, &block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems all this doc stuff is repeated from above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, copied to mirror how |
||
fields_for(scope || model, model, **options, &block) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dhh added the fields method to do: form_with(model: @post) do |form|
form.fields(:comment, model: @comment) do |fields|
fields.text_field # ...
end
end But it reads a bit weird if the passed Not sure if you intended this to be much more than a |
||
|
||
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object | ||
# assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation | ||
# is found in the current I18n locale (through helpers.label.<modelname>.<attribute>) or you specify it explicitly. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this needs the same fixes from above.