How to locate the location of the error when submitting a form form?

when the form form is submitted, there is an error to show the bubble, but locate the input error and then display the location

Mar.18,2021

there are three kinds of tests.

  1. Front-end check. We know which one is checked at this time, so it is easy to locate
  2. .
  3. the backend is all checked together. In this case, you can return the error message with the corresponding name, such as {info: 'xxx', name:' xxx'}, and the front end finds the corresponding input box according to name
  4. .
  5. the front and rear end is combined with verification. In this case, the backend is a single asynchronous check and the front end is Synchronize check. It is easy to locate, but to control the verification sequence, those that cannot be verified at the backend are always one beat slower. You can use the queue to wait for the last verification to complete before continuing with the subsequent verification.

this is divided into many situations.

< H2 > check what? < / H2 >
  • if it is a check format, then there can be a full front-end check.
  • if you need to check the database, such as account already exists, sensitive words need to be checked by ajax access server.
< H2 > how to check? < / H2 >

it feels like an input item and a check item. In fact, there is no need to do this, we can check all items every time we enter one. In fact, this is also more stringent.
write the corresponding verification method, this method should correspond to each input, how should we verify the mobile phone number, how to verify the password, and how to verify the address. The corresponding method is only responsible for the corresponding input,. If the check fails, the verification function can be located to the current input . For example, the verification method receives the id. of input
if it is sent uniformly to the background for verification, the backend will return the specific error field and the cause of the error.

< H2 > when will it be checked? < / H2 >

from an on-demand point of view, you can check when the input box is out of focus or when the value is changed. When to trigger it all depends on the demand.

Menu