I am building a form where a user can edit some personal details (such as name, location, etc). I am using a custom built field constructor, and I have no problems with this in other places.
@form(action = routes.Persons.update(), 'class -> "well well-lg form-horizontal"){
<fieldset>
@inputText(updateForm("forname"), '_label -> "First name", 'class -> "form-control")
@inputText(updateForm("surname"), '_label -> "Last name", 'class -> "form-control")
@inputText(updateForm("email"), '_label -> "Email", 'class -> "form-control")
@inputPassword(updateForm("passwordHash"), '_label -> "Password", 'class -> "form-control")
</fieldset>
<button type="submit" class="btn btn-primary">Update</button>
}
This works. I want the user to be able to edit his first name, last name and location, however, and not the email which he is registered with. I first attempted adding 'disabled -> true to the email input, but this broke the form (password, for example, was no longer pre-filled, and I get a [IllegalStateException: No value] error when the form is posted. A similar issue is discussed here, but my issue goes further. I can't simply leave the email field out of the form. The code looks like this:
@form(action = routes.Persons.update(), 'class -> "well well-lg form-horizontal"){
<fieldset>
@inputText(updateForm("forname"), '_label -> "First name", 'class -> "form-control")
@inputText(updateForm("surname"), '_label -> "Last name", 'class -> "form-control")
@inputPassword(updateForm("passwordHash"), '_label -> "Password", 'class -> "form-control")
</fieldset>
<button type="submit" class="btn btn-primary">Update</button>
}
When I try this, the form is again broken and I get the same IllegaleStateException
when it is posted... the problem is not, I believe, in the controller, as everything works fine as long as the email field is present...
My suspicion is that this is caused by the fact that I have a @constraint
on email in the model. Can someone confirm this? And how can I bypass this, so that I can have a prefilled form which is linked to an object, but where I can edit just a some of the attributes?
Thanks for any help!