mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
fix validations
This commit is contained in:
parent
2c04e1cf3d
commit
6496fd30fa
5 changed files with 26 additions and 20 deletions
|
@ -86,6 +86,11 @@ textarea {
|
|||
background: $danger_color;
|
||||
}
|
||||
|
||||
span.help-block {
|
||||
background: $danger_color;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* hform is used for 30em inline 2-element textinput/button forms */
|
||||
.hform .field {
|
||||
display: flex;
|
||||
|
|
|
@ -105,19 +105,15 @@ defmodule Philomena.Filters.Filter do
|
|||
|
||||
defp validate_search(changeset, field) do
|
||||
user_id = get_field(changeset, :user_id)
|
||||
user = if user_id, do: User |> Repo.get!(user_id)
|
||||
|
||||
if user_id do
|
||||
user = User |> Repo.get!(user_id)
|
||||
output = Query.user_parser(user, get_field(changeset, field))
|
||||
output = Query.compile(user, get_field(changeset, field))
|
||||
|
||||
case output do
|
||||
{:ok, _} -> changeset
|
||||
_ ->
|
||||
changeset
|
||||
|> add_error(field, "is invalid")
|
||||
end
|
||||
else
|
||||
changeset
|
||||
case output do
|
||||
{:ok, _} -> changeset
|
||||
_ ->
|
||||
changeset
|
||||
|> add_error(field, "is invalid")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -23,12 +23,12 @@ defmodule Philomena.Search.Parser do
|
|||
{tree, []} = unquote(:"#{name}_top")(ctx, tokens)
|
||||
|
||||
{:ok, tree}
|
||||
# rescue
|
||||
# e in ArgumentError ->
|
||||
# {:error, e.message}
|
||||
rescue
|
||||
e in ArgumentError ->
|
||||
{:error, e.message}
|
||||
|
||||
# _ ->
|
||||
# {:error, "Parsing error."}
|
||||
_ ->
|
||||
{:error, "Parsing error."}
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
.form
|
||||
= form_for @filter, @route, fn f ->
|
||||
= if @filter.action do
|
||||
#error_explanation
|
||||
' Oops, something went wrong! Please check the errors below.
|
||||
|
||||
.field
|
||||
= text_input f, :name, class: "input input--wide", placeholder: "Name"
|
||||
= error_tag f, :name
|
||||
.fieldlabel
|
||||
' This is a friendly name for this filter - it should be short and descriptive.
|
||||
.field
|
||||
|
@ -20,6 +25,8 @@
|
|||
= label f, :spoilered_complex_str, "Complex Spoiler Filter"
|
||||
br
|
||||
= textarea f, :spoilered_complex_str, class: "input input--wide", autocapitalize: "none"
|
||||
br
|
||||
= error_tag f, :spoilered_complex_str
|
||||
.fieldlabel
|
||||
p
|
||||
' Use the search syntax here to specify an additional filter.
|
||||
|
@ -42,6 +49,8 @@
|
|||
= label f, :hidden_complex_str, "Complex Hide Filter"
|
||||
br
|
||||
= textarea f, :hidden_complex_str, class: "input input--wide", autocapitalize: "none"
|
||||
br
|
||||
= error_tag f, :hidden_complex_str
|
||||
.fieldlabel
|
||||
p
|
||||
' Use the search syntax here to specify an additional filter.
|
||||
|
|
|
@ -41,8 +41,6 @@ h1
|
|||
|
||||
= for tag <- @spoilered_tags do
|
||||
= render PhilomenaWeb.TagView, "_tag.html", tag: tag
|
||||
|
||||
p Complex filter:
|
||||
pre.spoiler-filter-code
|
||||
= @filter.spoilered_complex_str
|
||||
|
||||
|
@ -55,8 +53,6 @@ h1
|
|||
|
||||
= for tag <- @hidden_tags do
|
||||
= render PhilomenaWeb.TagView, "_tag.html", tag: tag
|
||||
|
||||
p Complex filter:
|
||||
pre.spoiler-filter-code
|
||||
= @filter.hidden_complex_str
|
||||
|
||||
|
|
Loading…
Reference in a new issue