Last active
August 29, 2015 13:55
-
-
Save mashijp/8768399 to your computer and use it in GitHub Desktop.
バリデーションを全部Formのところに追いやった(play framework)
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
/** | |
* プロバイダ編集・追加フォーム | |
* | |
* @param provider 追加時はNone, 編集時は編集対象を渡す | |
*/ | |
private def providerForm(provider: Option[Provider] = None) = Form( | |
mapping( | |
"name" -> text.verifying(Provider.isValidName _), | |
"alias" -> text.verifying(Provider.isValidAlias _).verifying("既にこのAliasは使われています", alias => { | |
withDatabaseSession { | |
implicit ds => | |
provider.map(_.alias).exists(_ == alias) || new ProviderRepository().findByAlias(alias).isEmpty | |
} | |
}) | |
)((name, alias) => | |
provider.map { | |
p => | |
p.copy(name = name, alias = alias) | |
}.getOrElse(Provider(id = Provider.generateId(), name = name, alias = alias)) | |
)(e => Some((e.name, e.alias))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コレジャナイ感がすごい