generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Form object for due validation
- Loading branch information
1 parent
2c4ed0c
commit 7188cdd
Showing
5 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Support | ||
class CaseEvaluationDueDateForm < Form | ||
option :evaluation_due_date, Types::DateField | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Support | ||
class CaseEvaluationDueDateFormSchema < ::Support::Schema | ||
config.messages.top_namespace = :case_evaluation_due_date_form | ||
|
||
params do | ||
required(:evaluation_due_date).value(:hash) | ||
end | ||
|
||
rule :evaluation_due_date do | ||
if value.blank? | ||
key.failure(:missing) | ||
end | ||
end | ||
|
||
rule :evaluation_due_date do | ||
if value.present? && !hash_to_date.call(value) | ||
key.failure(:invalid) | ||
end | ||
end | ||
|
||
rule :evaluation_due_date do | ||
if value.present? | ||
date = hash_to_date.call(value) | ||
if date && date <= Time.zone.today | ||
key.failure(:must_be_in_the_future) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters