Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Forms 在scala窗体上仅显示一条错误消息_Forms_Scala_Playframework_Playframework 2.2 - Fatal编程技术网

Forms 在scala窗体上仅显示一条错误消息

Forms 在scala窗体上仅显示一条错误消息,forms,scala,playframework,playframework-2.2,Forms,Scala,Playframework,Playframework 2.2,我在scala表单中显示错误时遇到了一个小问题 在单个字段的scala表单上,我做了两项检查,如: val startForm = Form( single( "fooField" -> text.verifying(LengthError, { Util.isLengthCorrect(_) }).verifying(EmptyError, { !_.isEmpty }), )) 因此,当表单中显示错误消息时,如果两个检查条件都未完全填写,则

我在scala表单中显示错误时遇到了一个小问题

在单个字段的scala表单上,我做了两项检查,如:

    val startForm = Form(
        single(
          "fooField" -> text.verifying(LengthError, { Util.isLengthCorrect(_) }).verifying(EmptyError, { !_.isEmpty }),
))
因此,当表单中显示错误消息时,如果两个检查条件都未完全填写,则会显示两条错误消息,而此时只应显示一条

我只能手动显示第一个错误,如下所示:

@for(error <- startForm.errors("fooField")) {
                            <dd class="error">@Messages(error.message,0)</dd>
                            }
def oneAtATime[T](first: Constraint[T], second: Constraint[T]) =
  new Constraint[T](None, Seq()) { t: T =>
    first(t) match {
      case Valid => second(t)
      case other => other
    }
  }

@for(error您必须创建自己的方式来组合两个约束[T],如果第一个约束通过,它将只计算第二个约束。类似如下:

@for(error <- startForm.errors("fooField")) {
                            <dd class="error">@Messages(error.message,0)</dd>
                            }
def oneAtATime[T](first: Constraint[T], second: Constraint[T]) =
  new Constraint[T](None, Seq()) { t: T =>
    first(t) match {
      case Valid => second(t)
      case other => other
    }
  }

如果您想使用表单帮助程序只显示一个错误,这可能是不可能的。您必须自己创建一个错误。