ciro
ciro

Reputation: 801

materialize best practice validate empty field

i use this form

<div class="row">
    <form class="col s12">
        <div class="row">
            <div class="input-field col s12">
                <input id="email2" type="email" class="validate">
                <label for="email2" data-error="wrong" data-success="right">Email</label>
            </div>
            <div class="input-field col s12">
                <input id="example" name="example" type="text" class="validate" required="" aria-required="true">
                <label for="example" data-error="wrong" data-success="right">Field</label>
            </div>
        </div>
    </form>
</div>

mail field is ok. if I post in an incorrect mail address error message appears.

example field not work. i would check if field is not empty and then show error.

What's wrong?

Upvotes: 7

Views: 39527

Answers (2)

Gabriel White
Gabriel White

Reputation: 11

comment to ichadhr's comment

/** FIXES for error messages */

label {
    width: 100%;
}
.input-field label:not(.active):after {
    font-size: 0.8rem;
    -webkit-transform: translateY(-140%);
    -moz-transform: translateY(-140%);
    -ms-transform: translateY(-140%);
    -o-transform: translateY(-140%);
    transform: translateY(-140%);
}

Upvotes: 1

ichadhr
ichadhr

Reputation: 644

You forgot to add required="" and aria-required="true" here is the completes snippet:

<div class="row">
    <form class="col s12">
        <div class="row">
            <div class="input-field col s12">
                <input id="email2" type="email" class="validate" required="" aria-required="true">
                <label for="email2" data-error="wrong" data-success="right">Email</label>
            </div>
            <div class="input-field col s12">
                <input id="example" name="example" type="text" class="validate" required="" aria-required="true">
                <label for="example" data-error="wrong" data-success="right">Field</label>
            </div>
            <div class="input-field col s12">
                <button class="btn waves-effect waves-light" type="submit" name="action">Submit</button>
            </div>
        </div>
    </form>
</div>

http://jsfiddle.net/u76rdq2h/

Upvotes: 19

Related Questions