When validating a form with
form.bindFromRequest.fold(
formWithErrors => {
BadRequest(Json.toJson(formWithErrors)(/*implicit writes goes here*/))
},
data => {}
)
is there a standard Json Writes for the form with errors?
When validating a form with
form.bindFromRequest.fold(
formWithErrors => {
BadRequest(Json.toJson(formWithErrors)(/*implicit writes goes here*/))
},
data => {}
)
is there a standard Json Writes for the form with errors?
Ha, stupid me I just needed to define it
implicit val myFormDataWrites = Json.writes[MyFormData]
implicit val myFormDataFormWrites = Json.writes[Form[MyFormData]]
Stupid me once again. Intellij wasn’t showing my compile errors for this. You don’t need to write a Json writes macro for form errors You can just use
formWithErrors.errorsAsJson
So my original code should look like this
form.bindFromRequest.fold(
formWithErrors => {
BadRequest(formWithErrors.errorsAsJson)
},
data => {
/*do stuff with valid data*/
}
)