How to check the correct buttons using formvalidation.io and jQuery?

I am using the amazingSurge jquery-wizard plugin along with the formvalidation.io plugin. My intention is to perform form validation after the user wants to take a step forward in the wizard. This is great for regular input validation as well as for checking checkboxes. However, I am having trouble confirming the input form of the radio signal. The form only allows me a step forward when I select the first switch. When I have 20 switches in the form, and I select the third, the form check says that I did not select anything!

Here is my verification code:

$('#employeeForm').formValidation({ framework: 'bootstrap', fields: { employeeInput: { validators: { notEmpty: { message: 'Please choose an employee' } } } } }); wizard = $("#exampleWizardForm").wizard(options).data("wizard"); wizard.get("#employees").setValidator(function() { var fv = $("#employeeForm").data("formValidation"); return fv.validate(), fv.isValid() ? !0 : !1 }); // add validation after form was dynamically created $('#employeeForm').formValidation('addField', $("#employeeInput")); 

Here is my form:

 <form id="employeeForm" novalidate="novalidate" class="fv-form fv-form-bootstrap"> <div class="table-responsive"> <table class="table table-hover text-right"> <tbody id="employee_items"> <tr> <td class="text-center"> <label><input type="radio" value="196" name="employeeInput" id="employeeInput" kl_vkbd_parsed="true"></label> </td> <td class="text-left">Employee 1</td> <td>Software Tester</td> </tr> <tr> <td class="text-center"> <label><input type="radio" value="200" name="employeeInput" id="employeeInput" kl_vkbd_parsed="true"></label> </td> <td class="text-left">Employee 2</td> <td>Software Engineer</td> </tr> <tr> <td class="text-center"> <label><input type="radio" value="201" name="employeeInput" id="employeeInput" kl_vkbd_parsed="true"></label> </td> <td class="text-left">Employee 3</td> <td>CEO</td> </tr> </tbody> </table> </div> 

Am I missing something? Why is the form validation for radio inputs not working as desired?

enter image description here

+6
source share
2 answers

It looks like you should wrap your switches inside the form-group class, since you are using the bootstrap framework. For instance:

 $('#employeeForm').formValidation({ framework: 'bootstrap', icon: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { employeeInput: { validators: { notEmpty: { message: 'Please choose an employee' } } } } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/formValidation.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/bootstrap.js"></script> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> <form id="employeeForm" novalidate="novalidate" class="fv-form fv-form-bootstrap"> <div class="table-responsive"> <table class="table table-hover text-right"> <tbody id="employee_items" class="form-group"> <tr> <td class="text-center"> <label> <input type="radio" value="196" name="employeeInput" id="employeeInput" kl_vkbd_parsed="true"> </label> </td> <td class="text-left">Employee 1</td> <td>Software Tester</td> </tr> <tr> <td class="text-center"> <label> <input type="radio" value="200" name="employeeInput" id="employeeInput" kl_vkbd_parsed="true"> </label> </td> <td class="text-left">Employee 2</td> <td>Software Engineer</td> </tr> <tr> <td class="text-center"> <label> <input type="radio" value="201" name="employeeInput" id="employeeInput" kl_vkbd_parsed="true"> </label> </td> <td class="text-left">Employee 3</td> <td>CEO</td> </tr> </tbody> </table> </div> 
+2
source

you need to change the identifiers All three switches have the same employeeInput ID This is not true You can only have one unique element Id per dom Therefore change the Identification Names

+2
source

All Articles