Skip to content

Instantly share code, notes, and snippets.

@mariussoutier
Created August 2, 2012 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mariussoutier/3237595 to your computer and use it in GitHub Desktop.
Save mariussoutier/3237595 to your computer and use it in GitHub Desktop.
repeat helper with index
package views.html.helper
import play.api.templates.Html
object repeatWithIndex {
def apply(field: play.api.data.Field, min: Int = 1)(f: (play.api.data.Field, Int) => Html) = {
(0 until math.max(if (field.indexes.isEmpty) 0 else field.indexes.max + 1, min)).map(i => f(field("[" + i + "]"), i))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment