Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
播放(Scala)自定义表单类型验证_Scala_Playframework_Playframework 2.0 - Fatal编程技术网

播放(Scala)自定义表单类型验证

播放(Scala)自定义表单类型验证,scala,playframework,playframework-2.0,Scala,Playframework,Playframework 2.0,在我看来,我正在创建一个单选按钮,其值为0,1,2(字符串) 在我的模型中,我使用时间作为整数值,而radiobox没有选择以整数形式提交输入 因此,在我的控制器中,我考虑将时间输入转换为整数,并检查值是否在0-2之间 val dayForm = Form( mapping( "id" -> optional(longNumber), "time" -> <what can I do here to avoid type mismatch?>,

在我看来,我正在创建一个单选按钮,其值为0,1,2(字符串)

在我的模型中,我使用时间作为整数值,而radiobox没有选择以整数形式提交输入

因此,在我的控制器中,我考虑将时间输入转换为整数,并检查值是否在0-2之间

val dayForm = Form(
  mapping(
    "id" -> optional(longNumber),
    "time" -> <what can I  do here to avoid type mismatch?>,
    "date" -> sqlDate("yyyy-MM-dd") (Entry.apply)(Entry.unapply)
这将导致表单无法验证,因为输入字符串尚未转换。

我认为您可以编写

val dayForm = Form(
    mapping(
    "id" -> optional(longNumber),
    "time" -> number (min =0, max =2),
    "date" -> sqlDate("yyyy-MM-dd")
    )((id, time, date) => Entry(id, convertFunction(time), date))
    ((entry: Entry) => Some(entry.id, inverseFunction(entry.time), entry.date))
)
"time" -> number (min =0, max =2)
val dayForm = Form(
    mapping(
    "id" -> optional(longNumber),
    "time" -> number (min =0, max =2),
    "date" -> sqlDate("yyyy-MM-dd")
    )((id, time, date) => Entry(id, convertFunction(time), date))
    ((entry: Entry) => Some(entry.id, inverseFunction(entry.time), entry.date))
)