Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of Concept - Pre-selecting components using data object #1316

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

36degrees
Copy link
Member

This is a rough proof of concept that shows how we could 'extend' the macros from GOV.UK Frontend (with the additions in alphagov/govuk-frontend#2616) to pre-check / select radios, checkboxes and select using the stored data in the data object.

Check out this branch and run it then take a look https://localhost:3000/test for a demo.

A random collection of thoughts in no particular order:

  • This currently requires changes to app/views/layout.html which is in 'user land' – not ideal, but that's where we currently do the imports…
  • I suspect we'd want to add the filters somewhere else outside of the app directory, but added them for now just to prove it works
  • I'm not sure how we'd make this play nicely with the extensions framework, but at the minute the imports from GOV.UK Frontend are hard-coded anyway…
  • It'd be trivial to add similar for inputs and textareas, but date input might be harder… 🤔

@lfdebrux
Copy link
Member

This is pretty cool!

My main thoughts about this work (and the related piece alphagov/govuk-frontend#2616) is how it is documented. We probably don't want to telling users about multiple methods to achieve the same thing? But then we do have the issue of how do we make sure that they are reading the right documentation for the version of prototype kit they are using...

@joelanman
Copy link
Contributor

re opening as this is something we want to investigate further

@joelanman joelanman reopened this Feb 16, 2023
@frankieroberto
Copy link
Contributor

I like this! The implementation works how I'd expect it do, ie once you specify a name attribute, there’s no further work to do. Behind the scenes, the prototype kit would just set the value attribute and then pass all the params to the macro from govuk-frontend.

This could still be overridden if you set an explicit value attribute, which would make this largely backwards-compatible?

The only complication would be for "nested" attributes, which either Express or the prototype kit maps to name values using square brackets (I’ve never dug into how this works).

So this:

govukTextInput({"name": "things[a1][name]", ...})

would have to get converted to this:

govukTextInput({"value": data["things"]["a1"]["name"]})

...unless there’s a better way that I don’t know about?

(We use these nested attributes where users need to add multiple of a thing, with a random key generated for each thing that’s then used in the URL route)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants