Matthew Phelan
3 years ago
18 changed files with 150 additions and 84 deletions
@ -1,25 +0,0 @@ |
|||||||
class FormController < ApplicationController |
|
||||||
|
|
||||||
FIRST_QUESTION_FOR_SUBSECTION = { |
|
||||||
"Household characteristics" => "case_logs/household/tenant_code", |
|
||||||
"Household situation" => "case_logs/household_situation/previous_housing_situation" |
|
||||||
} |
|
||||||
|
|
||||||
NEXT_QUESTION = { |
|
||||||
"tenant_code" => "case_logs/household/tenant_age", |
|
||||||
"tenant_age" => "case_logs/household/tenant_gender", |
|
||||||
"tenant_gender" => "case_logs/household/tenant_ethnic_group", |
|
||||||
"tenant_ethnic_group" => "case_logs/household/tenant_nationality" |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
def next_question |
|
||||||
subsection = params[:subsection] |
|
||||||
result = if subsection |
|
||||||
FIRST_QUESTION_FOR_SUBSECTION[subsection] |
|
||||||
else |
|
||||||
NEXT_QUESTION[params[:previous_question]] |
|
||||||
end |
|
||||||
render result |
|
||||||
end |
|
||||||
end |
|
@ -1,7 +1,18 @@ |
|||||||
import { Controller } from "@hotwired/stimulus" |
// Visit The Stimulus Handbook for more details
|
||||||
|
// https://stimulusjs.org/handbook/introduction
|
||||||
|
//
|
||||||
|
// This example controller works with specially annotated HTML like:
|
||||||
|
//
|
||||||
|
// <div data-controller="hello">
|
||||||
|
// <h1 data-target="hello.output"></h1>
|
||||||
|
// </div>
|
||||||
|
|
||||||
|
import { Controller } from "stimulus" |
||||||
|
|
||||||
export default class extends Controller { |
export default class extends Controller { |
||||||
|
static targets = [ "output" ] |
||||||
|
|
||||||
connect() { |
connect() { |
||||||
this.element.textContent = "Hello World!" |
this.outputTarget.textContent = 'Hello, Stimulus!' |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,14 +1,9 @@ |
|||||||
import { Application } from "@hotwired/stimulus" |
// Load all the controllers within this directory and all subdirectories.
|
||||||
|
// Controller files must be named *_controller.js.
|
||||||
|
|
||||||
const application = Application.start() |
import { Application } from "stimulus" |
||||||
|
import { definitionsFromContext } from "stimulus/webpack-helpers" |
||||||
// Configure Stimulus development experience
|
|
||||||
application.warnings = true |
|
||||||
application.debug = false |
|
||||||
window.Stimulus = application |
|
||||||
|
|
||||||
// Import and register all your controllers within this directory and all subdirectories
|
const application = Application.start() |
||||||
// Controller files must be named *_controller.js or *_controller.ts
|
const context = require.context("controllers", true, /_controller\.js$/) |
||||||
import { definitionsFromContext } from "@hotwired/stimulus" |
|
||||||
const context = require.context("controllers", true, /_controller\.(js|ts)$/) |
|
||||||
application.load(definitionsFromContext(context)) |
application.load(definitionsFromContext(context)) |
||||||
|
@ -1,8 +0,0 @@ |
|||||||
<%= form_with model: @case_log, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
|
||||||
<%= f.govuk_number_field :age, |
|
||||||
hint: { text: "More detail" }, |
|
||||||
label: { text: "What is the tenant's age?", size: "l"}, |
|
||||||
min: 0, max: 150, step: 1, width: 20 |
|
||||||
%> |
|
||||||
<%= f.govuk_submit %> |
|
||||||
<% end %> |
|
@ -1,11 +1,12 @@ |
|||||||
<%= turbo_frame_tag "case_log_form" do %> |
<%= turbo_frame_tag "case_log_form" do %> |
||||||
<%= form_with action: '/form', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
<%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
||||||
<%= f.govuk_number_field :tenant_age, |
<%= f.govuk_number_field :tenant_age, |
||||||
hint: { text: "More detail" }, |
hint: { text: "More detail" }, |
||||||
label: { text: "What is the tenant's age?", size: "l"}, |
label: { text: "What is the tenant's age?", size: "l"}, |
||||||
min: 0, max: 150, step: 1, width: 20 |
min: 0, max: 150, step: 1, width: 20 |
||||||
%> |
%> |
||||||
<%= f.hidden_field :previous_question, value: :tenant_age %> |
<%= f.hidden_field :previous_question, value: :tenant_age %> |
||||||
|
<%= f.hidden_field :case_log_id, value: case_log_id %> |
||||||
<%= f.govuk_submit "Save and continue" %> |
<%= f.govuk_submit "Save and continue" %> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
@ -1,11 +1,12 @@ |
|||||||
<%= turbo_frame_tag "case_log_form" do %> |
<%= turbo_frame_tag "case_log_form" do %> |
||||||
<%= form_with action: '/form', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
<%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
||||||
<%= f.govuk_text_field :tenant_code, |
<%= f.govuk_text_field :tenant_code, |
||||||
hint: { text: "More detail" }, |
hint: { text: "More detail" }, |
||||||
label: { text: "What is the tenant code?", size: "l"}, |
label: { text: "What is the tenant code?", size: "l"}, |
||||||
width: 20 |
width: 20 |
||||||
%> |
%> |
||||||
<%= f.hidden_field :previous_question, value: :tenant_code %> |
<%= f.hidden_field :previous_question, value: :tenant_code %> |
||||||
|
<%= f.hidden_field :case_log_id, value: case_log_id %> |
||||||
<%= f.govuk_submit "Save and continue" %> |
<%= f.govuk_submit "Save and continue" %> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
Loading…
Reference in new issue