0

I am trying to show custom error validation messages using Materialize and HTML5 input validation. The error is detected (invalid pseudo-class shows up) but the validation error message isn't displayed.

This example from Materialize works fine (the framework should handle the custom error if the data-error attribute is set):

      <div class="input-field col s12">
        <input id="email" type="email" class="validate">
        <label for="email" data-error="wrong" data-success="right">Email</label>
      </div>

But not one of my fields:

 <div class="input-field col s12 m6">
      <input id="firstname" 
             type="text" 
             min-length="2"
             max-length="25" 
             pattern="^[a-zA-Z]+$" 
             class="validate" 
             required autofocus><br>
      <label for="firstname" 
             data-error="{{_ 'user_register_error_bad_firstname'}}" 
             data-success="ok">{{_ "first_name"}}</label>
  </div>

Basically, I want the field value to match a regex pattern, only letters in this case.

I assume that I misused the validation data attributes but I don't get how. Or maybe Materialize doesn't handle pattern based errors? Any idea?

Note that the {{_ 'something'}} syntax is just a SpaceBar i18n helper call.

5
  • oninvalid="this.setCustomValidity('{{_ 'user_register_error_bad_firstname'}}')"? Commented Apr 4, 2016 at 14:33
  • Materialize should call setCustomValidity this if I set the data-error attribute afaik Commented Apr 4, 2016 at 14:36
  • And it does not work either with a direct call. Weird... Commented Apr 4, 2016 at 14:38
  • Hmm, sorry I don't know Materialize. Commented Apr 4, 2016 at 14:40
  • Thank you for your help anyway :) Commented Apr 4, 2016 at 14:41

1 Answer 1

0

Holy cow, it all happened because I had a lost <br> between my input and my label...

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.