I need to use form input without any validation. (value is optional) so i tried to use optional type in form but its pop up some error. Simply I need to do is create a form with 4 input fields and 3 of them need to validate as text values only and another field with optionally (its value can be empty or not) and its not validate in the form submission
Read from stdout: D:\PROJECTS\test\Project_VendorM6\app\models\ProductSearch.scala:6: not found: type optional D:\PROJECTS\test\Project_VendorM6\app\models\ProductSearch.scala:6: not found: type optional Read from stdout: case class ProductSearch(proname: String,brandid:String,typeid:String,supplierid:optional[String]) case class ProductSearch(proname: String,brandid:String,typeid:String,supplierid:optional[String]) Read from stdout: ^
here is my form validation in controller
import play.api.data.Form
import play.api.data.Forms.{mapping, nonEmptyText,bigDecimal,text,number,optional}
private val productSearchForm: Form[ProductSearch] = Form(
mapping(
"proname" -> text,
"probrand" -> text,
"protype" -> text,
"prosup" -> optional(text)
)(ProductSearch.apply)(ProductSearch.unapply)
)
And here is my Model
package models
import play.api.db._
import play.api.Play.current
import scala.collection.mutable.ListBuffer
case class ProductSearch(proname: String,brandid:String,typeid:String,supplierid:optional[String])
object ProductSearch {
}
I tried it without the optional key word in model as follows
case class ProductSearch(proname: String,brandid:String,typeid:String,supplierid:String)
but then its pop-up two compile errors
Read from stdout: D:\PROJECTS\test\Project_VendorM6\app\controllers\Products.scala:39: type mismatch; Read from stdout: found : (String, String, String, String) => models.ProductSearch Read from stdout: required: (String, String, String, Option[String]) => ?
and
Read from stdout: D:\PROJECTS\test\Project_VendorM6\app\controllers\Products.scala:39: missing arguments for method unapply in object ProductSearch; Read from stdout: follow this method with
_' if you want to treat it as a partially applied function D:\PROJECTS\test\Project_VendorM6\app\controllers\Products.scala:39: missing arguments for method unapply in object ProductSearch; follow this method with_' if you want to treat it as a partially applied function Read from stdout: )(ProductSearch.apply)(ProductSearch.unapply) )(ProductSearch.apply)(ProductSearch.unapply)