0

I'm using BootstrapValidator plugin to validate a form, however i have following problem. I have a "Phone" field and a "Mobile" field if the user does not enter either of them, I wanted to launch a custom message (you need to inform one phone number), and if he inform any (phone or mobile) validation would be satisfied.

The doubt is: Is it possible to use conditional inside BootstrapValidator?

0

1 Answer 1

1

This seems to be working for a lot of people derived from this post:

$('form').validate({
    rules: {
        Phone: {
            required: true
        },
        Mobile: {
            required: true
        }
    },
    highlight: function(element) {
        $(element).closest('.form-group').addClass('has-error');
    },
    unhighlight: function(element) {
        $(element).closest('.form-group').removeClass('has-error');
    },
    errorElement: 'span',
    errorClass: 'help-block',
    errorPlacement: function(error, element) {
        if(element.parent('.input-group').length) {
            error.insertAfter(element.parent());
        } else {
            error.insertAfter(element);
        }
    }
});

and the html:

<form>
    <div class="form-group">
        <label class="control-label" for="Phone">Phone:</label>
        <div class="input-group">
            <input class="form-control" name="Phone" type="text" />
        </div>
    </div>

    <div class="form-group">
        <label class="control-label" for="Mobile">Mobile:</label>
        <div class="input-group">
            <input class="form-control" name="Mobile" type="text" />
        </div>
    </div>

        <button type="submit" class="btn btn-primary">Submit</button>
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.