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

Validation #321

Closed
wants to merge 5 commits into from
Closed

Validation #321

wants to merge 5 commits into from

Conversation

abbott567
Copy link
Contributor

Added basic validation for prototypes.

In this PR, I have set up a simple way to check for required inputs that are either blank or not selected.

  • Created validation.js and added it to includes/scripts
  • Created MD documentation to cover markup for each input type
  • Added MD documentation to 'Tutorials and Examples' page
  • Covered with tests

Validation demo


function checkTextFields (errors) {
$(document).find('input[type="text"], textarea').each(function () {
var $fieldset = $(this).parents('fieldset')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be closest instead of parents. Closest stops at the closest, parents looks at all parents for any possible matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good shout @joelanman there is a lot of parents() in there that could be changed

function checkTextFields (errors) {
$(document).find('input[type="text"], textarea').each(function () {
var $fieldset = $(this).parents('fieldset')
var label = $(this).parent().find('label').clone().children().remove().end().text()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be easier to read and understand if it was split into two or three operations, rather than one long chain


function checkTextFields (errors) {
$(document).find('input[type="text"], textarea').each(function () {
var $fieldset = $(this).parents('fieldset')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you use $(this) multiple times in this block, might be better to do var $this = $(this) once at the start

@joelanman
Copy link
Contributor

Just wondering whether we can remove the requirement to wrap elements in fieldset? It adds a lot of extra code and I'm not sure it's semantically correct to wrap single elements.

And to confirm - this just covers required - no other validation?

@joelanman
Copy link
Contributor

I think we should try and use the markup from elements:

https://govuk-elements.herokuapp.com/errors/#highlight-errors

happy to have a bash at that

@abbott567
Copy link
Contributor Author

Yeah, I originally tried to do that, but then it became more confusing in the documentation telling people where to put the data-require attribute. It seemed easier for the sake of prototyping (whilst not necessarily semantically correct) to add it to a wrapper, rather than saying 'if its a text field, put it on the input, if its radio buttons put it on the fieldset, if there are more than two fields in a group then add it somewhere else, if its a text area add it somewhere else etc. It might be the best approach, but consistency seemed easier to explain.

@abbott567
Copy link
Contributor Author

Happy to work with you to implement it that way though. Would probably make more sense to just work a bit harder on the documentation!

@joelanman
Copy link
Contributor

joelanman commented Jan 6, 2017

ah of course - you need something for radios, we could just use <div>

@abbott567 abbott567 closed this Apr 6, 2017
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.

2 participants