Topic: Adding error messages to text input fields
josephloius
free
asked 6 years ago
manuelcua
pro
answered 5 years ago
input[type=date].invalid+label:after, input[type=date]:focus.invalid+label:after, input[type=datetime-local].invalid+label:after, input[type=datetime-local]:focus.invalid+label:after, input[type=email].invalid+label:after, input[type=email]:focus.invalid+label:after, input[type=number].invalid+label:after, input[type=number]:focus.invalid+label:after, input[type=password].invalid+label:after, input[type=password]:focus.invalid+label:after, input[type=search-md].invalid+label:after, input[type=search-md]:focus.invalid+label:after, input[type=search].invalid+label:after, input[type=search]:focus.invalid+label:after, input[type=tel].invalid+label:after, input[type=tel]:focus.invalid+label:after, input[type=text].invalid+label:after, input[type=text]:focus.invalid+label:after, input[type=time].invalid+label:after, input[type=time]:focus.invalid+label:after, input[type=url].invalid+label:after, input[type=url]:focus.invalid+label:after, textarea.md-textarea.invalid+label:after, textarea.md-textarea:focus.invalid+label:after { white-space: nowrap; }
Magdalena Obalska free commented 5 years ago
@manuelcua, thank you for sharing your solution.Tanguy Lesseliers pro commented 5 years ago
@manuelcua, works as a charm ! Thank you The message was still displayed much lower than the field, so I added transform: translateY(-150%); kr Tanguymanuelcua pro commented 5 years ago
@Tanguy_Lesseliers No need to add that, you have to add the class "form-control" to your input and it will display correctly just under the input field line.Tanguy Lesseliers pro commented 5 years ago
Hi Magdalena, input has follwoing class = class="form-control validate" remove "validate"?
Tanguy Lesseliers
pro
answered 5 years ago
manuelcua pro commented 5 years ago
Yes, I get the same error, please where do I fix the squeezed text
Tanguy Lesseliers
pro
answered 5 years ago
Hi ,
I'm using laravel with mdboostrap.
I made a register modal and I'm using the form validation. when I submit the data to laravel 5.4 it can respond with an additional validation error. e.g. "email already registered". I managed to set this content in the "data-error" , ( attribute is present in the label) , but how can I get this displayed?
This is the email control in the registering modal:
<!-- email --> <div class="row"> <div class="col-md-12"> <div class="md-form form-sm"> <i class="fa fa-envelope darken-4 prefix"></i> <input type="email" name="email" id="email" class="form-control validate" tabindex="6"> <label for="email">@lang('login.register.label.email')</label> </div> </div> </div>
this is the javascript to handle the error json response
.fail(function(data) { $.each(data.responseJSON, function (key, value) { var input = '#formRegister input[name=' + key + ']'; $(input + '+label').attr('data-error',value); });
This is the final result :
<label for="email" class="active" data-error="L'adresse e-mail doit être unique">E-mail</label>
However the message is not visible.
Tanguy Lesseliers pro commented 5 years ago
found out that adding "invalid" as class to the control actually shows the error. However, the error is shown in a very small block and thus making it hard to read. <a href="https://drive.google.com/file/d/0B7tvep-UmnD1MHNvM3JUUVBBdlk/view?usp=sharing">Example screenshot</a>Magdalena Obalska free commented 5 years ago
Ok, I'm glad, that you found out what the problem is. Thank you for the message.
Magdalena Obalska
free
answered 6 years ago
Juan Ramos Suyón
free
answered 6 years ago
josephloius
free
answered 6 years ago
Bartłomiej Malanowski
staff
answered 6 years ago
<label for="form9" data-error="E-mail address seems to be invalid" data-success="What a good e-mail">Type your email</label>
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- User: Free
- Premium support: No
- Technology: General Bootstrap questions
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No