Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iterable/play-formnolia
https://github.com/iterable/play-formnolia
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/iterable/play-formnolia
- Owner: Iterable
- License: apache-2.0
- Created: 2018-03-04T21:11:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-07T09:51:52.000Z (over 6 years ago)
- Last Synced: 2024-11-24T11:11:59.338Z (2 months ago)
- Language: Scala
- Size: 15.6 KB
- Stars: 1
- Watchers: 69
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# play-formnolia
[![Travis CI](https://travis-ci.org/Iterable/play-formnolia.svg?branch=master)](https://travis-ci.org/Iterable/play-formnolia) [![Maven](https://img.shields.io/maven-central/v/com.iterable/play-formnolia_2.12.svg)](https://mvnrepository.com/artifact/com.iterable/play-formnolia_2.12)
A project to automatically generate and validate Play forms using [Magnolia](https://magnolia.work/).
## Example
```scala
// Add the required imports:
import com.iterable.formnolia.SafeForms._
import play.api.data.format.Formats._// Create a case class representing the form:
case class UserData(
username: String,
firstName: String,
lastName: String,
avatarUrl: Option[String]
)// Generate the form and bind it in a Play action (or elsewhere).
newForm[UserData].bindFromRequest().fold(
{ formWithErrors =>
BadRequest(s"Errors: ${formWithErrors.errors}")
},
{ userData =>
Ok(s"Got $userData")
}
)```