diff --git a/15-multi-step-form/src/main/resources/templates/step2.html b/15-multi-step-form/src/main/resources/templates/step2.html index 6a414ae..60e0b5b 100644 --- a/15-multi-step-form/src/main/resources/templates/step2.html +++ b/15-multi-step-form/src/main/resources/templates/step2.html @@ -110,7 +110,11 @@

You have the option of monthly or yearly billing.

-
+
@@ -191,6 +201,9 @@ role="switch" id="packageDuration" th:checked="${formData.userAnswers.step2.isYearly}" + hx-get="/step2/planTypeInputs" + hx-target="#plan-type-inputs" + hx-swap="outerHTML" />

+ cask.Response("Can't find answers for your session, please reload the page", 404) + case Some(answers) => { + // here changing yearly/monthly part of state based on passed checkbox value + // only for purposes of rendering the fragment + // not persisting, unless next or previous buttons are pressed + val withYearlyParamSet = answers.copy(step2 = answers.step2.copy(isYearly = isPackageYearlyBool)) + val formData = Models.FormData(withYearlyParamSet) + val context = new Context() + context.setVariable(formDataContextVarName, formData) + val planTypesInputsHtml = templateEngine.process( + "step2", + Set("planTypesInputs").asJava, + context + ) + println(s"updating plan type inputs for $answers") + cask.Response( + planTypesInputsHtml, + headers = Seq("Content-Type" -> "text/html;charset=UTF-8") + ) + } + } + } + @cask.staticResources("/public") def publicFiles() = "public"