Form validation


Topic: Form validation

Belovol pro asked 6 years ago

Good morning! How could I check validity of form's fields from within submitHandler() ? Code here only sets was-validated class to form element, so I can see incorrect input.  But I need to make desizion - post data or wait for subsequent correcting input? PS. By the way - something's been broken in this form. There is not confirming message. I've posted one question 6 times yesterday and my IP was banned (so now I use mobile phone). And I'm not alone.

Jakub Mandra staff premium answered 6 years ago

Form Validation uses html built in validation in association with Bootstraps classes. You can use state to display your custom messages.

Belovol pro answered 6 years ago

Thank you. I'd discovered that there is construction like e.target.validity.valid and it resolves all my troubles.

ppotter10 answered 5 years ago

Belovol's answer didn't work for me, but you can call a function reportValidity():

e.target.reportValidity()

This returns true if the form is valid and false otherwise. @staff: would be nice to document this.


Piotr Glejzer staff commented 5 years ago

Thanks for the report, we will add this to our docs. Have a nice day!


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.7.1
  • Device: 4xIntel Core i7-4510U CPU @2 GHz
  • Browser: Google Chrome V- 68.0.3440.8
  • OS: openSUSE Leap 42.3
  • Provided sample code: No
  • Provided link: Yes