Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap form validation not working without console error

This is Simple form.

This is JS code:

$(document).ready(function() {
  $('#ledgerHolderjHolderFormEdit').bootstrapValidator({
    feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
      JH_INIT: {
        validators: {
          notEmpty: {
            message: "'First Name' is required."
          },
          regexp: {
            regexp: /^07[a-zA-Z0-9.,:;!-@#\$%\^\&*\)\(+=_-`~><|].+$/,
            message: "'Mobile Number' must only start with '07'."
          },
          stringLength: {
            min: 5,
            max: 30,
            message: "'First Name' must be more than 2 and less than 255 characters long."
          }
        }
      }
    }
  });
});

There are no errors show in console, and could not find errors. Can anyone help me?

like image 768
Chanaka Hettiarachchi Avatar asked Dec 06 '17 11:12

Chanaka Hettiarachchi


People also ask

How to validate a bootstrap form?

In this demo, the Bootstrap form validation is done by using the default behavior. Only the required attribute is added for the fields. Go to the demo page and press the submit button and see how validation message appears:

What is the difference between valid and invalid feedback in Bootstrap?

The div with a class .valid-feedback is the form validation message success. The div with a class . invalid-feedback is the form validation message error. Each class stated above needs to be used together below the input field and then bootstrap with the help of JavaScript will determine which one to show based on user entry upon form submission.

How to validate a form without using JavaScript?

You can actually put the .was-validated class to the form tag even without the help of JavaScript but that will automatically show the form validation states and messages even before the user submits the form.

What is Bootstrap invalid bootstrap?

Bootstrap scopes the :invalid and :valid styles to parent.was-validated class, usually applied to the <form>. Otherwise, any required field without a value shows up as invalid on page load. This way, you may choose when to activate them (typically after form submission is attempted).


2 Answers

Solution Found

There are no effect in form and js. Issue was, I wrote html form in 'edit function'(append html form using jQuery). And after validation function wrote in another function. That is the reason.

After many efforts, I wrote validation inside that 'edit function'. The issue was solved.

like image 70
Chanaka Hettiarachchi Avatar answered Oct 24 '22 04:10

Chanaka Hettiarachchi


Make sure you've included JQuery correctly

like image 2
waqas Avatar answered Oct 24 '22 03:10

waqas