Materialize: Checkbox "validate" not showing/implemented

Created on 27 Jan 2016  路  5Comments  路  Source: Dogfalo/materialize

Native validation on checkboxes is important. The first example that comes to mind is to confirm having read the Terms of Service before registering to said service.

However, it does not seem to work, despite using the same syntax as for other input fields:

<div class="input-field no-margin col s12 m9">
    <input type="checkbox" name="accept" id="regTOS" required class="validate">
    <label for="regTOS" data-error="You must accept the Terms of Service">I accept the Terms of Service</label>
</div>

Most helpful comment

Since i really wanted to show the native validation, I removed the left: -9999px property and added margin-top: 8px; just so it lines up a little nicer.

All 5 comments

I'm also encountering this, even when I convert the submit to an input (which I don't think makes a difference).

So this is because of the css overrides to the native input selector. See:

[type="checkbox"]:not(:checked), [type="checkbox"]:checked {
     position: absolute;
     left: -9999px;
     opacity: 0;
}

I'm not sure how you would resolve this. Seems there would need to be some kind of hook into the native require input api to display the message below this custom selector overriding the input element.

Since i really wanted to show the native validation, I removed the left: -9999px property and added margin-top: 8px; just so it lines up a little nicer.

Confirmed, like newswim wrote, I've used:

[type=checkbox]:not(:checked) {
    left: inherit;
    margin-top: 8px;
}

...and it works fine.

Fixed in 57423d86

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Robouste picture Robouste  路  3Comments

serkandurusoy picture serkandurusoy  路  3Comments

onigetoc picture onigetoc  路  3Comments

acierpinski picture acierpinski  路  3Comments

cope picture cope  路  3Comments