Skip to content

Commit

Permalink
Represent checkbox options as seq rather than seq
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNickWilson committed Sep 25, 2019
1 parent b798662 commit 9086e0c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/g8/app/views/components/input_checkboxes.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
legendClass: Option[String] = None,
hint: Option[String] = None,
trackGa: Boolean = false,
inputs: Set[RadioOption]
inputs: Seq[RadioOption]
)(implicit messages: Messages)

@hintBlock = {
Expand Down Expand Up @@ -43,7 +43,7 @@
@errorBlock
@for((RadioOption(id, value, messageKey), index) <- inputs.zipWithIndex) {
@defining(
inputs.toSeq.indices.flatMap { i =>
inputs.indices.flatMap { i =>
field(s"[\$i]").value
}
) { answers =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait CheckboxFieldBehaviours extends FormSpec {

def checkboxField[T](form: Form[_],
fieldName: String,
validValues: Set[T],
validValues: Seq[T],
invalidError: FormError): Unit = {
for {
(value, i) <- validValues.zipWithIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait CheckboxViewBehaviours[A] extends ViewBehaviours {
def checkboxPage(form: Form[Set[A]],
createView: Form[Set[A]] => HtmlFormat.Appendable,
messageKeyPrefix: String,
options: Set[RadioOption],
options: Seq[RadioOption],
fieldKey: String = "value",
legend: Option[String] = None): Unit = {

Expand Down
9 changes: 5 additions & 4 deletions src/main/scaffolds/checkboxPage/app/models/$className$.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ object $className$ extends Enumerable.Implicits {
case object $option1key;format="Camel"$ extends WithName("$option1key;format="decap"$") with $className$
case object $option2key;format="Camel"$ extends WithName("$option2key;format="decap"$") with $className$

val values: Set[$className$] = Set(
$option1key;format="Camel"$, $option2key;format="Camel"$
val values: Seq[$className$] = Seq(
$option1key;format="Camel"$,
$option2key;format="Camel"$
)

val options: Set[RadioOption] = values.map {
val options: Seq[RadioOption] = values.map {
value =>
RadioOption("$className;format="decap"$", value.toString)
}

implicit val enumerable: Enumerable[$className$] =
Enumerable(values.toSeq.map(v => v.toString -> v): _*)
Enumerable(values.map(v => v.toString -> v): _*)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class $className$ControllerSpec extends SpecBase with MockitoSugar {

"populate the view correctly on a GET when the question has previously been answered" in {

val userAnswers = UserAnswers(userAnswersId).set($className$Page, $className$.values).success.value
val userAnswers = UserAnswers(userAnswersId).set($className$Page, $className$.values.toSet).success.value

val application = applicationBuilder(userAnswers = Some(userAnswers)).build()

Expand All @@ -62,7 +62,7 @@ class $className$ControllerSpec extends SpecBase with MockitoSugar {
status(result) mustEqual OK

contentAsString(result) mustEqual
view(form.fill($className$.values), NormalMode)(fakeRequest, messages).toString
view(form.fill($className$.values.toSet), NormalMode)(fakeRequest, messages).toString

application.stop()
}
Expand Down

0 comments on commit 9086e0c

Please sign in to comment.