Answer the question
In order to leave comments, you need to log in
How to highlight invalid form fields?
Nothing to add to the title of the question. There is an assumption that you can add a class to empty or incorrectly filled fields and hang styles on the class.
Question: how to do it?
Form code below:
Answer the question
In order to leave comments, you need to log in
Just search the MDN site. All approaches are consecrated there, at least with this case
https://developer.mozilla.org/en/docs/Learn/HTML/F...
Here is an example with boostrapom ajax. ajax returns wrong names
$.ajax({
url: url,
type: method,
enctype: 'multipart/form-data',
data: data,
processData: false,
contentType: false,
cache: false,
success: function(response) {
callback(response);
},
error: function(response) {
$.each(response.responseJSON.errors, function (i, error) {
let el = $(form).find('[name="'+i+'"]');
el.addClass('is-invalid');
el.after($('<div class="invalid-feedback">'+error[0]+'</div>'));
});
}
}
});
Why not use the browser's Contraint Validation API? Then the selection of an invalid form will be caught by the usual CSS selector:
form:invalid {
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question