I
I
Ivan Medvedev2020-05-05 17:48:29
css
Ivan Medvedev, 2020-05-05 17:48:29

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

3 answer(s)
V
Vladimir Korotenko, 2020-05-05
@firedragon

Just search the MDN site. All approaches are consecrated there, at least with this case
https://developer.mozilla.org/en/docs/Learn/HTML/F...

E
ediboba, 2020-05-06
@ediboba

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>'));
                });
            }
        }
    });

P
Pavel Lovtsevich, 2020-05-14
@lautsevich

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 {
   ...
}

Because I advise you to use the API, which is not ideal in its architecture, through not directly, but through the Bouncer.js library . On the Costraint Validation API, I have an introduction to the topic. It's a little outdated, but the base is the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question