I have a form with two fields - empno and name . Both values ββare populated with a default value. When displayed in a view, I want empno to be read-only and name to be editable.
In the creation view, I use @leaveform.value.get.empno to display finished and work fine. The problem only occurs when inserting with an error ([NoSuchElementException: None.get]) .
Questions:
- The problem is the return error does not have the value property. What else can I use to get the value?
- Can I skip
@inputText for a read-only field?
See my code below:
// ***** CONTROLLER *****// val leaveform = Form[LeaveModel]( mapping( "empno" -> nonEmptyText, "name" -> nonEmptyText )((no, empno) => LeaveModel(empno, name)) ((leave: LeaveModel) => Some(leave.empno, leave.name)) ) def create = withAuth { username => implicit request => // Define default values val empno = "STUDENT" val name = "" // Set default values val filledForm = leaveform.fill(LeaveModel(empno,name)) Ok(html.leave.form(filledForm)) } def insert = Action ( implicit request => { leaveform.bindFromRequest.fold( error => { BadRequest(html.leave.form(error)) // Question 1. Here is the error. }, leave => { LeaveModel.insert(leave) Redirect(routes.indexController.index()) } ) } ) // ***** VIEW START***** // @(leaveform: Form[LeaveModel]) @leaveform.value.get.empno @helper.form( action = (routes.LeaveController.update(oid)), 'id -> "leaveform") { @inputText(leaveform("empno")) // Question 2. @inputText(leaveform("name")) }
source share