Am generating a hidden fields like so:
@helper.input(_form("userID"), '_label-> None) { (id, name, value, args) =>
<input type="hidden" name="@name" id="@id" value="@value" @toHtmlArgs(args)>
}
Which works fine except for the fact that the div wrapper block element is created, which creates visual empty space in the form, not looking good -- how to make hidden input elements display without div wrapper?
I know I can jQuery hide the parent div wrapper, but I'd like to not generate it in the first place.
You don't need to use a @helper.input
in this case. Try this:
@defining(_form("userID")) { uidField =>
<input type="hidden" name="@uidField.name" id="@uidField.id" value="@uidField.value">
}
Although the question has already been answered, I'd like to give a complete example because this would have helped me alot.
You may define your own hidden input helper in a file called "app/views/helper/inputHidden.scala.html" that would look like:
@**
* Generate a hidden HTML input.
*
* Example:
* {{{
* @inputHidden(field = myForm("name"), args = 'data-ref -> 0)
* }}}
*
* @param field The form field.
* @param args Set of extra attributes.
* @param handler The field constructor.
*@
@(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: FieldConstructor, lang: play.api.i18n.Lang)
@id = @{ args.toMap.get('id).map(_.toString).getOrElse(field.id) }
@inputType = @{ args.toMap.get('type).map(_.toString).getOrElse("hidden") }
@htmlArgs = @{ args.filter(arg => !arg._1.name.startsWith("_") && arg._1 != 'id).toMap.filter(_._1 != 'type) }
<input type="@inputType" id="@id" name="@field.name" value="@field.value" @toHtmlArgs(htmlArgs)>
This allows you to reuse the code in all your views and to give additional parameters like data-ref="..."
to your hidden field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With