docs: auto? docs improvements

This commit is contained in:
Zach Daniel 2023-03-20 10:22:07 -04:00
parent 057e7fd426
commit 5d4703414b
2 changed files with 27 additions and 22 deletions

View file

@ -1,4 +1,25 @@
defmodule AshPhoenix.Form.Auto do
@auto_opts [
relationship_fetcher: [
type: :any,
doc: """
A two argument function that receives the parent data, the relationship to fetch.
The default simply fetches the relationship value, and if it isn't loaded, it uses `[]` or `nil`.
"""
],
sparse_lists?: [
type: :boolean,
doc:
"Sets all list type forms to `sparse?: true` by default. Has no effect on forms derived for embedded resources.",
default: false
],
include_non_map_types?: [
type: :boolean,
doc: "Creates form for non map or array of map type inputs",
default: false
]
]
@moduledoc """
A tool to automatically generate available nested forms based on a resource and action.
@ -40,6 +61,10 @@ defmodule AshPhoenix.Form.Auto do
render a search form for that read action, and once they've selected a record, you could render the fields
to update that record (in the case of `on_lookup: :relate_and_update` configurations).
## Options
#{Spark.OptionsHelpers.docs(@auto_opts)}
## Special Considerations
### `on_lookup: :relate_and_update`
@ -60,27 +85,6 @@ defmodule AshPhoenix.Form.Auto do
@dialyzer {:nowarn_function, rel_to_resource: 2}
@auto_opts [
relationship_fetcher: [
type: :any,
doc: """
A two argument function that receives the parent data, the relationship to fetch.
The default simply fetches the relationship value, and if it isn't loaded, it uses `[]` or `nil`.
"""
],
sparse_lists?: [
type: :boolean,
doc:
"Sets all list type forms to `sparse?: true` by default. Has no effect on forms derived for embedded resources.",
default: false
],
include_non_map_types?: [
type: :boolean,
doc: "Creates form for non map or array of map type inputs",
default: false
]
]
def auto(resource, action, opts \\ []) do
opts = Spark.OptionsHelpers.validate!(opts, @auto_opts)
Keyword.new(related(resource, action, opts) ++ embedded(resource, action, opts))

View file

@ -428,7 +428,8 @@ defmodule AshPhoenix.Form do
You can add additional nested forms by including them in the `forms` config alongside `auto?: true`.
See the module documentation of `AshPhoenix.Form.Auto` for more information. If you want to do some
manipulation of the auto forms, you can also call `AshPhoenix.Form.Auto.auto/2`, and then manipulate the
result and pass it to the `forms` option. To pass options, use `auto?: [option1: :value]`.
result and pass it to the `forms` option. To pass options, use `auto?: [option1: :value]`. See the
documentation of `AshPhoenix.Form.Auto` for more.
#{Spark.OptionsHelpers.docs(@nested_form_opts)}
"""