question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to prevent default browser input validation

See original GitHub issue

Currently there doesn’t seem to be any direct way to prevent the browser’s default validation behaviour. eg. when the form contains an input of type=“number” and you enter a non-number string and submit, then in Chrome the validation tooltip will appear on the input.

Standard way to disable this functionality on a normal form, would be to specify the novalidate attribute. This unfortunately doesn’t work with Formsy.Form.

Currently the only workaround I found was to wrap the Formsy.Form element in an outer form tag and specify novalidate there.

<form novalidate>
  <Formsy.Form>...</Formsy.Form>
</form>

But this will probably have some other disadvantages. Would be great if you could support the novalidate attribute! 😃

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
twistycommented, May 23, 2015

There’s another case where formNoValidate works:

<Formsy.Form>
   <input type="search" name="q" formNoValidate required />
</Formsy.Form>

I think what happens here is that in a form with a single “texty” type of input, that element also takes the role of the submit button, so formNoValidate applies and native validation is skipped.

In the docs, it maybe worth noting that formsy-react isn’t performing any “special magic”, and provide a link to the html5 spec?

1reaction
twistycommented, May 14, 2015

I think @dprentis is right, the formnovalidate attribute is only allowed on submit and image input types. So if it’s present on the default button for the form, native validation is skipped. If formnovalidate is not present on the default button, then a novalidate attribute on the form element comes into play.

From what I can see, adding formNoValidate to other inputs (as shown in the API documentation) has no effect.

Native validation shown:

<Formsy.Form>
   <input name="foo" formNoValidate required />
   <input name="submit" type="Submit" />
</Formsy.Form>

Native validation supressed:

<Formsy.Form>
   <input name="foo" required />
   <input name="submit" formNoValidate type="Submit" />
</Formsy.Form>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent the default browser input validation?
I've tried to implement event. preventDefault(); however it doesn't seem to work in my case.
Read more >
Avoid Default Field Validation - Adrian Roselli
I made an example on CodePen that uses an email field ( type="email" ), is required ( required ), and uses a pattern...
Read more >
Event.preventDefault() - Web APIs | MDN
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default ......
Read more >
Validation · Bootstrap v5.0
For custom Bootstrap form validation messages, you'll need to add the novalidate boolean attribute to your <form> . This disables the browser default...
Read more >
How to Manage Browser Defaults with event.preventDefault ...
Browsers have default interactions and behaviors for different events. For example, when a user clicks a "submit" button on a form, the form...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found