Last active
August 29, 2015 13:55
-
-
Save kunst1080/8769263 to your computer and use it in GitHub Desktop.
Play FrameworkのviewでConstraints.MaxLengthの値をmaxlengthに反映するフォームテンプレートヘルパー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: views.html.helper.FieldConstructor, lang: play.api.i18n.Lang) | |
@inputType = @{ args.toMap.get('type).map(_.toString).getOrElse("text") } | |
@maxLen = @{field.constraints.filter(_._1=="constraint.maxLength").map(_._2)} | |
@views.html.helper.input(field, args.filter(_._1 != 'type):_*) { (id, name, value, htmlArgs) => | |
<input type="@inputType" id="@id" name="@name" value="@value"@if(!maxLen.isEmpty){ maxlength="@maxLen"} @toHtmlArgs(htmlArgs)> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment