0

I have a Rails application that spits back out a form with backend validation error messages. The form itself uses HTML5 constraint validation on the frontend.

I'm running into an issue where when I submit a form that is invalid directly to the server, I get the expected behaviour that the form returns with the errors flagged from the backend, and the previous values filled out in the form.

However, all the fields on the form are reporting true when I run element.checkValidity() on them after the form returns back, regardless of the actual validity on them.

For example, on a <textarea> that is previously submitted with an error (minLength = 10, value.length = 2), the backend is correctly flagging the error and marking it.

But once I get the new form back, using JS, the element reports as valid.

temp2.validity
<- ValidityState {.... valid: true }

temp2.minLength
<- 10

temp2.value.length
<- 2

temp2.textLength
<- 2

temp2.checkValidity()
<- true

Anyone have any insight as to why this is happening?

I'm not sure what to try here, to be honest. My frontend validation is built on the constraint validation API, and it doesn't seem to be reporting the validity state correctly.

crespire
  • 33
  • 1
  • 7

0 Answers0