Created
August 2, 2012 14:49
-
-
Save mariussoutier/3237595 to your computer and use it in GitHub Desktop.
repeat helper with index
This file contains hidden or 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
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