Skip to content

Instantly share code, notes, and snippets.

@remeniuk
Created September 7, 2013 15:27
Show Gist options
  • Save remeniuk/6476563 to your computer and use it in GitHub Desktop.
Save remeniuk/6476563 to your computer and use it in GitHub Desktop.
val selectedBonusIdValidator = (form: Form[BonusForm]) =>
(for {
value <- form.value
bonusId <- value.selectedBonusId
} yield form
) getOrElse form.withError("selectedBonusId", "You should select an item!")
val selectedBonusValueValidator = (form: Form[BonusForm]) =>
(for {
value <- form.value
bonusId <- value.selectedBonusValue
} yield form
) getOrElse form.withError("selectedBonusValue", "You should provide the value!")
val form = (bonusForm.fill(formEntity) /:
List(selectedBonusIdValidator, selectedBonusValueValidator))((f, v) => v(f))
if (form.hasErrors) ... else ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment