Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Gladdish mgladdish

View GitHub Profile
@mgladdish
mgladdish / WidgetWithOnlyOneReportedConstraint.scala
Last active Jun 12, 2019
Shows an inputText with multiple constraints, only the first of which will be reported on the form
View WidgetWithOnlyOneReportedConstraint.scala
inputText("validationExample", "messages", firstOnly(required(), isNumber))
@mgladdish
mgladdish / WidgetWithMultipleConstraints.scala
Last active Jun 12, 2019
Shows an inputText with multiple constraints, each of which will be reported on the form
View WidgetWithMultipleConstraints.scala
inputText("validationExample", "messages", required() ++ isNumber)
View NestingFormDefinitionSnippet.scala
section(
messages = "sectionText", // the name of properties bundle containing section-level text
nestingCheckboxes(
"myCheckboxes", // the unique name of our widget
"questionWording", // the name of the properties bundle containing text for the widget
required, // constraints applied to the widget
"contactMethods", // the name of the properties bundle containing the key and labels for each checkbox choice
Map( // our nested widgets
View nestedInput.scala
def nestedInput[M <: Messages[M]](name: String, ...)(...) =
Input(name, ..., layoutTemplateName = "nestedWidgetBoilerplate.mustache", ...)
View nestingCheckboxes.mustache
{{#choices}}
<div class="multiple-choice">
<input id="{{id}}_{{value}}" name="{{name}}" type="checkbox" value="{{value}}" {{#selected}} checked="checked" {{/selected}} />
<label for="{{id}}_{{value}}">{{{text}}}</label>
</div>
{{{nestedWidget}}} <!-- addition to output the html of the already-rendered nested widget -->
{{/choices}}
View NestingCheckboxesV2.scala
case class NestingCheckboxes[C <: Messages[C]](... nestedWidgets: Map[String, Widget]) extends NestingMultipleChoice[C] {
override val nestingMultipleChoiceWidget = new Checkbox(...) {
override def render(form: Form, errors: ValidationErrors, requestInfo: RequestInfo)(...): Future[String] = {
...
// pass result of templateChoices(form, errors, requestInfo) to my template and return the rendered result
}
}
}
View NestingCheckboxesV1.scala
case class NestingCheckboxes[C <: Messages[C]](... nestedWidgets: Map[String, Widget]) extends NestingMultipleChoice[C] {
override val nestingMultipleChoiceWidget = new Checkbox(...)
}
View NestingMultipleChoiceV3.scala
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(...
View NestingMultipleChoiceV2.scala
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(...
@mgladdish
mgladdish / NestingMultipleChoiceV1.scala
Created Jun 12, 2018
First draft of a nesting multiple choice trait
View NestingMultipleChoiceV1.scala
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
}
You can’t perform that action at this time.