diff --git a/Gemfile b/Gemfile index c06fdf065..e0f82780a 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem "bootsnap", ">= 1.4.4", require: false # Gov.UK frontend components gem "govuk-components" gem "govuk_design_system_formbuilder" +gem 'hotwire-rails' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js new file mode 100644 index 000000000..5975c0789 --- /dev/null +++ b/app/javascript/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.textContent = "Hello World!" + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 000000000..4b51d5be3 --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,14 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// 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 +// Controller files must be named *_controller.js or *_controller.ts +import { definitionsFromContext } from "@hotwired/stimulus" +const context = require.context("controllers", true, /_controller\.(js|ts)$/) +application.load(definitionsFromContext(context)) diff --git a/app/views/form/age.html.erb b/app/views/form/age.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/form/index.html.erb b/app/views/form/index.html.erb index 920cdce3e..cb486d210 100644 --- a/app/views/form/index.html.erb +++ b/app/views/form/index.html.erb @@ -1,4 +1,5 @@ -<%= form_with url:'/test', builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_number_field :age, label: { text: "Age" } %> - <%= f.govuk_submit %> -<% end %> +<%= turbo_frame_tag "form" %> + <%= form_with url:'/test', builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_number_field :age, label: { text: "Age" } %> + <%= f.govuk_submit %> + <% end %> diff --git a/package.json b/package.json index 58f585adc..1811460fb 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "data-collector", "private": true, "dependencies": { + "@hotwired/stimulus": "^3.0.0-beta.1", + "@hotwired/turbo": "^7.0.0-rc.3", + "@hotwired/turbo-rails": "^7.0.0-rc.3", "@rails/actioncable": "^6.0.0", "@rails/activestorage": "^6.0.0", "@rails/ujs": "^6.0.0",