Search code examples
javascriptbootstrapvalidator

How to stop bootstrapValidator to validate hidden input fields?


I want to implement bootstrapValidator in my form and I have also some hidden input fields but It is validating those also, I want to stop this... My form code

<form id="create_contract_group" method="post"

 - List item

>
<div class="row">
  <div class="form-group">
    <label class="col-md-4 control-label"><b>{!!Lang::get('site_lang.contract_group')!!}</b></label>
       <div class="col-md-8">
          <input type="text" class="form-control" name="title" placeholder=" Title of the contract group"/>
          <input type="text" class="form-control" name="id" style="display:none">
       </div>
    </div>
 </div>
</form>

My script

<script>
$(document).ready(function() {
    $('#create_contract_group').bootstrapValidator({
            excluded: ':disabled',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {
                            message: 'Title is required.'
                        },
                        validatorName: validatorOptions
                    }
                },
            }
        });
});
</script>

Solution

  • You can use exludes setting in boostrapValidator, like below :

    $('#create_contract_group').bootstrapValidator({
                excluded: [':disabled', ':hidden', ':not(:visible)'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    title: {
                        validators: {
                            notEmpty: {
                                message: 'Title is required.'
                            },
                            validatorName: validatorOptions
                        }
                    },
                }
            });