lundi 6 juin 2016

Displaying HTML5 validation message for custom checkbox

My sign-up form uses HTML5 validation to validate that required fields have been completed.

<div class="container">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <form action="http://ift.tt/L0I4hY" method="POST" id="signup">
                <div class="form-group">
                    <label for="first_name">First name</label>
                    <input id="first_name" maxlength="40" name="first_name" size="20" type="text" class="form-control" required>
                </div>
                <div class="checkbox">
                    <label>
                        <input id="tou" name="tou" type="checkbox" value="1" required="required"/>
                        I have read and agree to the terms of use.
                    </label>
                </div>
                <input type="submit" name="submit" class="btn">
            </form>
        </div>
    </div>
</div>

I've replaced the default checkbox with a custom .svg checkbox using CSS.

input[type=checkbox] {
    display: inline-block;
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    visibility: hidden;
}

input[type=checkbox]:before {
    content: url(/static/img/unchecked.svg);
    visibility: visible;
}

input[type=checkbox]:checked:before {
    content: url(/static/img/checked.svg);
}

While the HTML5 validation works with other fields, I can't get it to work for the custom checkbox. I tried the methods shown in jQuery validation with custom CSS checkbox without success. Any ideas?




Aucun commentaire:

Enregistrer un commentaire