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

Bug or potential issue - show-hide-content.js #366

Closed
paulmsmith opened this issue Jan 10, 2017 · 5 comments
Closed

Bug or potential issue - show-hide-content.js #366

paulmsmith opened this issue Jan 10, 2017 · 5 comments

Comments

@paulmsmith
Copy link
Contributor

Hi,

Following up from a discussion with @dsingleton on XGOV Slack. I noticed a slight issue with the show-hide-content.js code.

If you examine line 83 you will see there is an assumption that the 'Conditionally revealing content' pattern will existing within a form element.

As I was quickly hacking together a prototype within the the govuk prototyping kit, I hadn't wrapped the markup in a form element and it broke silently (no errors or console warnings). It's an edge case but as there is now a firm movement toward modular builds of components this could bite people.

Simple short term suggestion, check for existence of a form element, else console log a developer friendly message.

Longer term, assume this will be replaced by what's delivered in GOVUK Front-end?

@robinwhittleton
Copy link
Contributor

@gemmaleigh bumped into this when adding radio buttons to GOV.UK Frontend – the selection button JS assumes a form as well. In that case we decided that we can drop the JS entirely given a change in markup, but here we probably just need a check for the existence of a form ancestor. Something like this might work?

var $form = $control.closest('form')
var $radios = $form.length ? $form.find(selector) : $(selector)

@paulmsmith
Copy link
Contributor Author

@robinwhittleton That looks fine to me. What's the reason for using closest? To restrict the affected radios to just those within the form that they are situated?

@robinwhittleton
Copy link
Contributor

Yes. Imagine a situation where you have two sets of radios with the same name attributes. Outside of a form or within the same form they’ll share the selected state toggling behaviour. In two seperate forms they’ll maintain two seperate toggle states.

@paulmsmith
Copy link
Contributor Author

I thought so but my brain was failing me. :) 👍

@paulmsmith
Copy link
Contributor Author

Nice. +1

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

No branches or pull requests

2 participants