Topic: MDBSelect Validation

fbischoff free asked 5 years ago


Hi All,

We are using the React's version of MDBoostrap. We need to add validation into the MDBSelect component. Like this if a user doesn't select an item, we need to show him an error message.

How can we achieve this ?

Best Regards


Aliaksandr Andrasiuk staff answered 5 years ago


Hi,

In that topic described a possible way to achieve that:

https://mdbootstrap.com/support/react/correct-way-to-validate-mdbselect-in-react-form/.

You can add ahandleSubmit function to the form's button. In that function, you can check if any value is selected. By default value is Choose your option, so you can compare selected value to Choose your option. If the condition is true than use e.preventDefault() so your form will not be submitted and you can show to a user an error message.

handleSubmit = (e) => {
        if (this.state.value === 'Choose your option') {
            e.preventDefault();
              ....
        }
    };

Best regards.



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

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.13.0
  • Device: Computer
  • Browser: Internet Explorer, Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No