-
Notifications
You must be signed in to change notification settings - Fork 36
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
introduce option validation for all backpex fields #661
base: develop
Are you sure you want to change the base?
Conversation
# Conflicts: # lib/backpex/fields/textarea.ex
type: {:fun, 1} | ||
], | ||
custom_alias: [ | ||
doc: "A custom alias for the field.", |
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.
@Flo0807 Feel free to suggest further information here (and for other options).
select: dynamic([user: u], fragment("concat(?, ' ', ?)", u.first_name, u.last_name)), | ||
} | ||
""", | ||
type: {:struct, Ecto.Query.DynamicExpr} |
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 get the following warning when generating the docs:
Generating docs...
warning: documentation references module "Ecto.Query.DynamicExpr" but it is hidden
│
134 │ @callback render_index_form(assigns :: map()) :: %Phoenix.LiveView.Rendered{}
│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│
└─ lib/backpex/field.ex:134: Backpex.Field (module)
But maybe thats not a problem?
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 also noticed that the placeholder is not used anymore (?) I guess, its because of this MR: #658
], | ||
prompt: [ | ||
doc: "The text to be displayed when no option is selected or function that receives the assigns.", | ||
type: :string |
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.
prompt
may also be a function with arity 1.
@config_schema [ | ||
options: [ | ||
doc: "List of options or function that receives the assigns.", | ||
type: {:or, [:keyword_list, {:fun, 1}]}, |
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.
options
may also be a list of tuples, e.g. [{"Admin", "admin"}]
. I think a list of strings can also be used. In the future, we may also have to support groups (like described here: https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html#options_for_select/2)
Maybe we just use {:list, :any}
instead of :keyword_list
for now?
Otherwise, we should allow all options that are allowed for options_for_select/2
. See https://github.com/phoenixframework/phoenix_html/blob/v4.1.1/lib/phoenix_html/form.ex#L303
@@ -1,17 +1,33 @@ | |||
# credo:disable-for-this-file Credo.Check.Design.DuplicatedCode | |||
defmodule Backpex.Fields.DateTime do | |||
@default_format "%Y-%m-%d %I:%M %p" | |||
@config_schema [ |
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.
readonly
(boolean or function of arity 1) is missing
@@ -1,17 +1,33 @@ | |||
# credo:disable-for-this-file Credo.Check.Design.DuplicatedCode | |||
defmodule Backpex.Fields.Date do | |||
@default_format "%Y-%m-%d" | |||
@config_schema [ |
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.
readonly
(boolean or function of arity 1) is missing
@@ -1,15 +1,29 @@ | |||
defmodule Backpex.Fields.Number do | |||
@config_schema [ |
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.
readonly
(boolean or function of arity 1) is missing
Define wether this field should be editable on the index view. Also see the | ||
[index edit](/guides/authorization/index-edit.md) guide. | ||
""", | ||
type: :boolean |
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.
index_editable
can also be a function of arity 1
], | ||
prompt: [ | ||
doc: "The text to be displayed when no option is selected or function that receives the assigns.", | ||
type: :string |
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.
prompt
can also be a function
|
||
The default value is `"Select options..."`. | ||
""", | ||
type: :string |
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.
prompt
can also be a function with arity 1
@config_schema [ | ||
options: [ | ||
doc: "List of options or function that receives the assigns.", | ||
type: {:or, [:keyword_list, {:fun, 1}]}, |
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.
Same issues as with Backpex.Fields.Select
options
], | ||
prompt: [ | ||
doc: "The text to be displayed when no option is selected or function that receives the assigns.", | ||
type: :string |
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.
prompt
can also be a function of arity 1
Before this MR, we allowed |
], | ||
accept: [ | ||
doc: "Required filetypes that will be accepted.", | ||
type: {:list, :string} |
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.
accept
can also be of type atom (= :any
). See https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#allow_upload/3-options
doc: "Required filetypes that will be accepted.", | ||
type: {:list, :string} | ||
], | ||
max_entries: [ |
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.
Add a default of 1 for max_entries
?
* `:meta` - The upload meta. | ||
* `:entry` - The upload entry. | ||
@config_schema [ | ||
upload_key: [ |
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.
LiveView also allows upload_key
(the name passed to allow_upload/3
) to be of type binary, but I guess this change would break some functionality in Backpex.
We don't use validated fields for:
|
Backpex.Field
when building custom fields