fix validations

This commit is contained in:
byte[] 2019-11-02 09:28:54 -04:00
parent 2c04e1cf3d
commit 6496fd30fa
5 changed files with 26 additions and 20 deletions

View file

@ -86,6 +86,11 @@ textarea {
background: $danger_color; background: $danger_color;
} }
span.help-block {
background: $danger_color;
display: block;
}
/* hform is used for 30em inline 2-element textinput/button forms */ /* hform is used for 30em inline 2-element textinput/button forms */
.hform .field { .hform .field {
display: flex; display: flex;

View file

@ -105,10 +105,9 @@ defmodule Philomena.Filters.Filter do
defp validate_search(changeset, field) do defp validate_search(changeset, field) do
user_id = get_field(changeset, :user_id) user_id = get_field(changeset, :user_id)
user = if user_id, do: User |> Repo.get!(user_id)
if user_id do output = Query.compile(user, get_field(changeset, field))
user = User |> Repo.get!(user_id)
output = Query.user_parser(user, get_field(changeset, field))
case output do case output do
{:ok, _} -> changeset {:ok, _} -> changeset
@ -116,9 +115,6 @@ defmodule Philomena.Filters.Filter do
changeset changeset
|> add_error(field, "is invalid") |> add_error(field, "is invalid")
end end
else
changeset
end
end end
defp parse_tag_list(list) do defp parse_tag_list(list) do

View file

@ -23,12 +23,12 @@ defmodule Philomena.Search.Parser do
{tree, []} = unquote(:"#{name}_top")(ctx, tokens) {tree, []} = unquote(:"#{name}_top")(ctx, tokens)
{:ok, tree} {:ok, tree}
# rescue rescue
# e in ArgumentError -> e in ArgumentError ->
# {:error, e.message} {:error, e.message}
# _ -> _ ->
# {:error, "Parsing error."} {:error, "Parsing error."}
end end
# #

View file

@ -1,7 +1,12 @@
.form .form
= form_for @filter, @route, fn f -> = form_for @filter, @route, fn f ->
= if @filter.action do
#error_explanation
' Oops, something went wrong! Please check the errors below.
.field .field
= text_input f, :name, class: "input input--wide", placeholder: "Name" = text_input f, :name, class: "input input--wide", placeholder: "Name"
= error_tag f, :name
.fieldlabel .fieldlabel
' This is a friendly name for this filter - it should be short and descriptive. ' This is a friendly name for this filter - it should be short and descriptive.
.field .field
@ -20,6 +25,8 @@
= label f, :spoilered_complex_str, "Complex Spoiler Filter" = label f, :spoilered_complex_str, "Complex Spoiler Filter"
br br
= textarea f, :spoilered_complex_str, class: "input input--wide", autocapitalize: "none" = textarea f, :spoilered_complex_str, class: "input input--wide", autocapitalize: "none"
br
= error_tag f, :spoilered_complex_str
.fieldlabel .fieldlabel
p p
' Use the search syntax here to specify an additional filter. ' Use the search syntax here to specify an additional filter.
@ -42,6 +49,8 @@
= label f, :hidden_complex_str, "Complex Hide Filter" = label f, :hidden_complex_str, "Complex Hide Filter"
br br
= textarea f, :hidden_complex_str, class: "input input--wide", autocapitalize: "none" = textarea f, :hidden_complex_str, class: "input input--wide", autocapitalize: "none"
br
= error_tag f, :hidden_complex_str
.fieldlabel .fieldlabel
p p
' Use the search syntax here to specify an additional filter. ' Use the search syntax here to specify an additional filter.

View file

@ -41,8 +41,6 @@ h1
= for tag <- @spoilered_tags do = for tag <- @spoilered_tags do
= render PhilomenaWeb.TagView, "_tag.html", tag: tag = render PhilomenaWeb.TagView, "_tag.html", tag: tag
p Complex filter:
pre.spoiler-filter-code pre.spoiler-filter-code
= @filter.spoilered_complex_str = @filter.spoilered_complex_str
@ -55,8 +53,6 @@ h1
= for tag <- @hidden_tags do = for tag <- @hidden_tags do
= render PhilomenaWeb.TagView, "_tag.html", tag: tag = render PhilomenaWeb.TagView, "_tag.html", tag: tag
p Complex filter:
pre.spoiler-filter-code pre.spoiler-filter-code
= @filter.hidden_complex_str = @filter.hidden_complex_str