How to Set HTML Validation Errors for Forms (Survey Form Test)?

I’m working on the Survey Form test and when I ran the tests almost all of the errors involve validation errors not returning properly. I was under the impression that you just needed to set the form input fields to “required” for validation errors to show when input isn’t completed, but this wasn’t covered in the course so I’m unsure how to proceed.

Here is codepen for the test for reference: https://codepen.io/callowaycodes/pen/wvKBPej

Any feedback would be much appreciated!

please include the test suite in your project

for the html validation, you need to use correct type attribute

Here is test suite: https://codepen.io/freeCodeCamp/pen/MJjpwO

that’s a pen with just the test suite, you need to add that script tag in your code

Oh my fault, I didn’t know how it worked initially and had just copied my code into that pen, I didn’t know you couldn’t see it when it was shared.

I’ve copied the test suite into my code now.

I don’t see it, have you saved the pen?

It was set to auto-save but guess it wasn’t saving lol, just manually saved!

look at the first line below the failed tests. It say why the test fail.

It seems you did not follow user stories exactly.

if you need help with specific user stories ask again

It says “input field with id=name should be a text field”.

My code shows:

<input type="text" id="name"

So I don’t understand the error. It seems I followed the instructions.

I figured it out. It’s because I had id set for label as well and not for just input. The error message was not an indicator of this.

important thing to remember: an id should be unique. when the tests search for something by id they will see only the first element with that id

Yeah that was my issue. I had same ID for label and input. Just wanted to note that incase anyone having same issue and sees this thread!

nyone having same issue and sees this thread! figured it out. It’s because I had id set for label as well and not for just input. The error message was not an indicator of this.