lift / framework

Lift Framework
http://liftweb.net
Apache License 2.0
1.27k stars 280 forks source link

Html5 support for fields #676

Closed davidB closed 2 months ago

davidB commented 14 years ago

Html5 introduce new attributes for input tag and allow client side form validations.

Currently I hacked lift-record source like following (But a more general solution will be better)


  //TODO find a better way to support html5 addtional attributes (and a way to transform every type of field)
  protected def elemAttr: MetaData = {
    val b = new UnprefixedAttribute("type", "text", Null) // to inject maxLength,...
    isHtml5 match {
      case true => {
        val b2 = regExp.map { x => new UnprefixedAttribute("pattern", x, b) }.getOrElse(b)
        new UnprefixedAttribute("required", (!optional_?).toString, b2)
      }
      case false => b
    }
  }

  protected def elem = S.fmapFunc(SFuncHolder(this.setFromAny(_))) { funcName =>
    val b = 
    b % elemAttr
  }

(full source at

And I override localForm method into User( extends MetaMegaProtoUser ) :


  override protected def localForm(user: User, ignorePassword: Boolean): NodeSeq = {
    signupFields.
    flatMap(fi => user.fieldByName(fi.name)).
    filter(f => !ignorePassword || (f match {
          case f: PasswordField[User] => false
          case _ => true
        })).
    flatMap(f =>
      f.toForm.toList.map(form =>
        (

{form. map{case e : Elem => e % new UnprefixedAttribute("required", (!f.optional_?).toString, Null)} }

) ) ) }

And to allow isHtml5 to return true I add into Boot.boot (lift:Html5 tag set the DocType too late):


   S.addAround(new LoanWrapper{
      def apply[T](f : => T) : T = {
        S.setDocType(Full(DocType.html5))
        f
      }
    })
github-importer commented 12 years ago

Imported from Assembla: http://www.assembla.com/spaces/liftweb/tickets/676

farmdawgnation commented 2 months ago

This issue / PR is being closed because the Lift community has decided to decomission the Lift Persistence group of libraries including Mapper, Record, et al. We encourage folks to check out using some alternatives for their persistence needs. In particular the following libraries may be of interest:

There are likely others, as well! Please feel free to reach out on the Lift Mailing List if you have any questions or concerns.