D
D
dizzy72016-12-31 18:16:34
Scala
dizzy7, 2016-12-31 18:16:34

Play scala forms. How to display data in a form that has not passed validation?

Good afternoon. If the form is filled out incorrectly, all fields are reset. I can't figure out how forms handle data when validation fails. There is a code:

postForm.bindFromRequest.fold(
        errors =>
          Ok(views.html.create(postForm)),
        postData => {
          Ok(views.html.create(postForm.fill(postData)))
        }
      )

In case of successful filling, you can call postForm.fill(postData) - and after the submission, the fields in the form remain filled. But in the case of an incorrectly filled form (for example, some of the fields are empty) - there is no postData object and all fields in the form are reset. How should such a situation be handled?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dizzy7, 2016-12-31
@dizzy7

The question is removed, set foot. The form with errors is passed to the first parameter, hence the correct code:

formWithErrors =>
          Ok(views.html.create(formWithErrors)),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question