playframework bind form checkbox 取值

直接上代码


case class Notice(notice_class:Int,title:String,content:String,appId:Option[List[Int]],platformId:Option[List[Int]],marketId:Option[List[Int]],channelId:Option[List[Int]])


The out of the box constraints are defined on the Forms object:

  • text: maps to scala.String, optionally takes minLength and maxLength.
  • nonEmptyText: maps to scala.String, optionally takes minLength andmaxLength.
  • number: maps to scala.Int, optionally takes minmax, and strict.
  • longNumber: maps to scala.Long, optionally takes minmax, and strict.
  • bigDecimal: takes precision and scale.
  • date: maps to java.util.Date, optionally takes pattern and timeZone.
  • email: maps to scala.String, using an email regular expression.
  • boolean: maps to scala.Boolean.
  • checked: maps to scala.Boolean.
  • optional: maps to scala.Option.

  val noticeForm= Form(
      mapping(
              "notice_class" -> number,
              "title" -> nonEmptyText,
              "content" -> nonEmptyText,
              "appId" -> optional(play.api.data.Forms.list(number)),
              "platformId" -> optional(play.api.data.Forms.list(number)),
              "marketId" -> optional(play.api.data.Forms.list(number)),
              "channelId" -> optional(play.api.data.Forms.list(number))
      )(Notice.apply)(Notice.unapply)
  )


注意checkbox的name
 @for(p <- platform) {
                           <input type="checkbox" id="@p.pid" name="platformId[@p.pid]" value="@p.pid"/> @p.pname
                       }


你可能感兴趣的:(framework,play,check)