Skip to content

Instantly share code, notes, and snippets.

@mgladdish
Created June 12, 2018 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgladdish/f25a55adc5a5270dd3188db48b9a5414 to your computer and use it in GitHub Desktop.
Save mgladdish/f25a55adc5a5270dd3188db48b9a5414 to your computer and use it in GitHub Desktop.
trait NestingMultipleChoice[C <: Messages[C]] extends WidgetGroup {
def nestedWidgets: Map[String, Widget]
def nestingMultipleChoiceWidget: MultipleChoice[C]
override lazy val widgets: Seq[Widget] = nestingMultpleChoiceWidget +: nestedWidgets.values.toSeq
def templateChoices(form: Form, errors: ValidationErrors, requestInfo: RequestInfo)(...): Future[List[Map[String, Any]]] = {
nestingMultipleChoiceWidget.choicesForTemplate.map(...
// Iterate through the choices already coverted to template params
// For each choice, find the associated nestedWidget by its key
// If there is an associated widget, add the result of calling nestedWidget.render(form, errors, requestInfo) to the template params
...
)
}
override def render(form: Form, errors: ValidationErrors, requestInfo: RequestInfo)(...): Future[String] =
nestingMultipleChoiceWidget.render(form, errors, requestInfo)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment