Commit Graph

147 Commits

Author SHA1 Message Date
bhumi1102
f0f624bde4
[RF-DOCS] Action View Form Helpers Guide [ci-skip] (#51936)
In addition to updating the code examples and editing text for clarity and flow, here some more details on some of the changes:

- [X] Do we still need an HTML5 warning at the end of the 1st section? It's pretty standard these days.
--> agree, removed.
- [X] Not sure the output of `_form_with model: @article`_ is 100% correct, might need to double check that.
--> yes. updated this example and got the HTML output from my "guides playground" rails app.
- [X] When we mention `record.persisted?` in record identification, could be a good plug to link to the Active Model guide on that.
--> Hm...there is no direction mention, other than this https://guides.rubyonrails.org/active_model_basics.html#conversion
- [X] Similar to STI, link to the guide / reference on it.
- [X] Time Zone and Country Select should likely be broken into separate sub-sections (I don't mind still mentioning country select)
- [X]  Would the file upload example would be better with a CSV for local processing, rather than showing saving to local disk? (which is probably a very uncommon usage?)
- [X] The _labeled_form_with_ example could likely be simplified with `_**options_` being all that it takes, instead of explicitly showing all possible kwargs.
- [X]  It may be better to show "complex forms" (section 10) right after the parameters (section 8), moving "forms to external resources" down... just because complex forms require exactly the fields_for incantation that was detailed further under the parameters section, so it seems a better continuation. (or potentially even reversed? complex forms then params? not sure)
- [X] Under "complex forms", adding fields on the flow could be slightly expanded, it feels very "go figure". 
--> Yeah, not sure what to do about this one. Was thinking about removing it as there is not built-in support to showcase.

---------

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
Co-authored-by: Amanda Perino <58528404+AmandaPerino@users.noreply.github.com>
Co-authored-by: Karl Lingiah <karl@superchilled.co.uk>
2024-06-28 17:49:36 +02:00
jbk2
aa688c1d31
Update form_helpers.md
Correcting book[title] value typo on line 265 in order that it correctly reflects it's object value stated in line 248.
2023-11-29 14:08:49 +01:00
Gannon McGibbon
847bd59268 [skip ci] Add composite primary key examples to Rails guides
- Action Controller Overview: Add example of how a cpk record can be
  found using a show action.
- Action View Form Helpers: Add example of what a form updating a cpk
  record looks like.
- Action View Helpers: Add examples for url_for and link_to cpk record
  urls.
2023-09-05 10:33:27 -05:00
Rafael Mendonça França
57b79cf162
Improve guide for Customizing form builder
Make the example complete so people can follow along insted of having
to understand the implicit context that you need an existing helper
called `text_field_with_label` to make the example work.

Fixes #49027.
2023-08-24 15:32:01 +00:00
zzak
175fab9bb6
Link to ActionView::Helpers top level namespace for all helpers
Co-authored-by: Mike Munroe <mike@oblsk.com>
2023-05-22 18:57:53 +09:00
Mike Munroe
77e048577a Link to Action View Form Helpers section in API 2023-04-27 21:37:00 -04:00
zzak
c3f2b545f8
Introduce markdownlint for guides
This is a follow up to rails#47186, this time for all markdown content.

[markdownlint](https://github.com/markdownlint/markdownlint) is an excellent tool, and I've found it very useful for finding issues in the guides.

Many of the rules are common style issues I'm correcting on PRs, so it will be nice to have that automated.

We should also be able to use the same config with our editors, so that errors show up in real-time 🙏 and will update the contributing docs once this gets merged with how to debug and use mdl appropriately.
2023-03-27 12:14:18 +09:00
zzak
dadf46de36
Add rubocop-md for linting guides snippets 2023-03-15 10:48:19 +09:00
hachi8833
dac61fa8f3 [ci-skip] Remove obsolete paragraph from form_helpers.md for Rails 7 2023-01-20 12:07:46 +09:00
Aditya Pandit
d83f52cede Fixed form helper documentation [ci-skip] 2022-12-08 23:56:06 +05:30
Missy Davies
d49a3abc01 Capitalize headings to match style guidelines
Fix all headings to follow Rails Guides Guidelines
2022-10-17 17:01:28 -10:00
Jonathan Hefner
66d8f8c14d
Merge pull request #45779 from jonathanhefner/guide-form_helpers-explicitly-mention-associations
Mention associations in Form Helpers guide [ci-skip]
2022-08-12 15:44:00 -05:00
Jonathan Hefner
a3a42f65e2 Mention associations in Form Helpers guide [ci-skip]
This fleshes out the "Choices from a Collection of Complex Objects"
section a bit more, explicitly mentioning associations and proper field
naming.
2022-08-12 15:36:50 -05:00
Jonathan Hefner
a713f7f22f Fix typos [ci-skip] 2022-08-05 21:36:18 -05:00
cjilbert504
4908a5a31f Update form_helpers.md section 1
The edits in section 1.2.1 of this guide are being proposed as the value argument passed to `check_box` is not in the second position, it is the third argument as shown [here](https://api.rubyonrails.org/v7.0.3/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box) and in turn the language around the argument list for `radio_button` in section 1.2.2 needed to be altered as well.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-05-26 18:00:18 -05:00
Claas Z
1cee625569
Update guides/source/form_helpers.md
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2022-05-11 16:48:34 +02:00
Claas Z
def782dfeb
Clarified requirements for keys in nested structures 2022-04-14 17:50:05 +02:00
Jesse Sousa
27a2129929
Fix typo 2022-03-13 21:07:06 -03:00
Jonathan Hefner
031f7af1d6 Improve fields_for helper sections [ci-skip]
Prior to this commit, there were two sections in the Form Helpers guide
with the same heading "The `fields_for` Helper".

This commit differentiates those two headings, and makes some minor
improvements to both sections for clarity.
2022-02-14 16:28:53 -06:00
Jonathan Hefner
4ae7acf00d Fix typos [ci-skip] 2022-02-13 13:07:51 -06:00
Caleb Stevens
8efd634cab Fix boolean error in form helpers guide 2021-11-24 01:01:53 -08:00
Alex Ghiculescu
b8ee5732db Simplify singular resource example
This:

```ruby
resource :geocoder
```

and this:

```ruby
  resource :geocoder
  resolve('Geocoder') { [:geocoder] }
```

create exactly the same routes. Thus, it's better to show the simpler example rather than imply that both method calls are needed.

`resolve` is used for [polymorphic routes](https://guides.rubyonrails.org/routing.html#using-resolve) but isn't necessary in this example.
2021-03-28 18:38:51 -05:00
Alex Ghiculescu
0fba70c082 Clarify when enctype="multipart/form-data" gets added to forms [docs]
As noted in https://github.com/rails/rails/issues/41632 the docs for this are incorrect. The `enctype` attribute is automatically added anytime you make a form with a `file_field`.

Resolves https://github.com/rails/rails/issues/41632

Update actionview/lib/action_view/helpers/form_helper.rb

Co-authored-by: Petrik de Heus <petrik@deheus.net>
2021-03-10 13:09:46 -06:00
Tim Tilberg
6210565e14
Update name of input to fix typo 2021-01-21 23:48:32 -06:00
Sean Doyle
b8c9c9d06f Translate FormBuilder#button calls with formmethod:
When submitting a `<form>`, browsers will serialize the element that
initiated the submission as part of the [FormData][], including its
`name` and `value` attributes.

Browser support for `<form>` submission HTTP verbs is limited to `GET`
and `POST`. Rails currently works around this [limitation by
constructing `<input type="hidden" name="_method" value="VERB">` which
serializes `_method="VERB"` to the FormData][_method].

To support varied HTTP actions within the same form, this commit
intervenes when a `form.button formmethod: "..."` call is made during
form construction, and translates any `formmethod:` value to the
corresponding work-around version.

[FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
[_method]: https://edgeguides.rubyonrails.org/form_helpers.html#how-do-forms-with-patch-put-or-delete-methods-work-questionmark
[button-formmethod]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formmethod
2021-01-08 18:21:02 -05:00
Jonathan Hefner
cb0da4f817 Fix typos, grammar, and formatting [ci-skip]
This is a collection of minor superficial improvements.  It does not
include any significant content changes.
2020-12-28 12:05:53 -06:00
Petrik
0a583c73c1 Change form_with to generate non remote forms by default
`form_with` would generate a remote form by default.
This confused users because they were forced to handle remote requests.

All new 6.1 applications will generate non-remote forms by default.
When upgrading a 6.0 application you can enable remote forms by default by
setting `config.action_view.form_with_generates_remote_forms` to `true`.
2020-12-01 21:14:37 +01:00
Jonathan Hefner
3d82ed1b5a
Merge pull request #40377 from jonathanhefner/guide-form_helpers-_tag-helpers
Mention _tag helpers in Form Helpers guide [ci-skip]
2020-10-13 11:53:21 -05:00
Jonathan Hefner
93391a7468
Merge pull request #40339 from jonathanhefner/guide-form_helpers-grouped-options
Add Option Groups section to Form Helpers guide [ci-skip]
2020-10-13 11:52:33 -05:00
Jonathan Hefner
140cf5c9fe Mention _tag helpers in Form Helpers guide [ci-skip]
This adds mention of the `*_tag` helpers provided by `FormTagHelper`,
and directs the reader to the API documentation for more information.
2020-10-13 10:47:31 -05:00
Jonathan Hefner
a6c426d986 Rework Date and Time Form Helpers section [ci-skip]
This shifts the primary focus from the bare `select_*` helpers to the
equivalent `FormBuilder#*_select` helpers.  It also links all covered
helpers to their API documentation.
2020-10-08 16:33:14 -05:00
Jonathan Hefner
c4503a92e1 Link API documentation more in Form Helpers guide [ci-skip]
This links the first mention of each helper to its API documentation,
similar to a Wikipedia article.
2020-10-06 10:35:50 -05:00
Jonathan Hefner
34c43d579c Add Option Groups section to Form Helpers guide [ci-skip]
This introduces option groups, how they are specified, and how they are
rendered.
2020-10-05 16:53:56 -05:00
Sam Jewell
fb36561dd6
Fix when duplicate params are accumulated
The previous statement was not strictly true all of the time.
For example, an input named `person[phone_number[]]` does
not get automatically accumulated. Updated this to a statement
that is always true (even if it may not fully describe all possible
cases, such as perhaps nested forms).
2020-09-28 09:20:21 +01:00
Jonathan Hefner
d118875dce Unify coverage of collection helpers [ci skip]
Follow-up to #39344.

This adds back coverage of `collection_select`, adds new coverage of
`collection_radio_buttons`, revises existing coverage of
`collection_check_boxes`, and unifies these sections.
2020-06-04 01:13:04 -05:00
Jonathan Hefner
e86e0147dc Mention text_area helper [ci skip]
Follow-up to #39344.

Adds back mention of `text_area` helper.
2020-06-03 23:38:56 -05:00
Jonathan Hefner
612eb35a5a Prefer form builder methods in Form Helpers guide [ci skip]
The Form Helpers guide should encourage users to use `form_with` and
associated builder methods.  The lower-level `*_tag` methods are covered
by the API docs.

These changes also fix some discrepancies between code examples and
their descriptions.
2020-05-24 19:04:36 -05:00
Jamie
7817996fc4
Fix references in the form builders guide [ci skip]
I caught two references that seemed inconsistent:

1. In section 2.2 Binding a Form to an Object, the code snippet variable was called `form`, but in the bullet points below, it was referenced as `f`.
2. In section 6 Uploading Files, the references to the params hash returned by two different forms was incorrect.
2020-05-18 14:55:23 -04:00
Eileen M. Uchitelle
f4a72c4aed
Merge pull request #37885 from gwincr11/cg-document-checkboxes
Document working with association and checkboxes in a form
2020-03-31 10:34:32 -04:00
Cory Gwin @gwincr11
20ba3b8e0a Document working with association and checkboxes in a form
Motivation:
  - I frequently look for this in the docs then struggle to rememeber
  the name of the function I need to find in the api docs. Also I think
  other people may benefit from it being easier to find.

Changes:
  - Added a section about Collection Checkboxes to the docs.

Co-Authored-By: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
2020-03-31 10:31:05 -04:00
Jonathan Hefner
f2cedf9151 Update form examples [ci skip]
Convert examples to use `form_with` instead of `form_for` or `form_tag`,
which have been soft-deprecated.  Also rename form variable in examples
from `f` to `form`, as exemplified by 8ff7ca5d11.
2019-11-01 18:10:36 -05:00
Kasper Timm Hansen
eca6c273fe
[ci skip] switch eg. to proper e.g. 2019-10-07 02:18:36 +02:00
David
99557b7281
Fixed pluralization typo 2019-10-06 12:19:55 -04:00
mario
f60bc890ee correct information about record identification
The description claimed that `.new_record?` was used in `form_for` to derive the action and button text.
But in the code `.persisted?` is used for that purpose.

[ci skip]
2019-10-04 07:20:31 +02:00
Akshay Mohite
c27be3bf21
Added missing comment notation for the example of form_with in form_helpers.md documentation. [ci skip] 2019-08-01 18:09:35 +05:30
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
Nathaniel Suchy
d9f1cc05b5 Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
tkoyama1988
b1ca79514e Improve readability in form helpers guide [ci skip] 2018-09-17 17:30:25 +09:00
Nicolas Maloeuvre
e7a3df190c [ci skip] Typo in form helpers guide 2018-08-30 22:23:54 +02:00
bogdanvlviv
841fc1837b
Update "Action View Form Helpers" guide [ci skip] 2018-08-27 19:24:38 +03:00