How to display only single validation error at a time

后端 未结 6 1672
失恋的感觉
失恋的感觉 2021-02-08 02:35

I have this code to which displaying errors on my form


&         


        
6条回答
  •  长发绾君心
    2021-02-08 03:09

    If you have consistent markup for your error message blocks, then you can use css to display only the first message and hide the rest:

    css

    .message-block .error-message {
      // Hidden by default
      display: none;
    }
    .message-block .error-message:first-child {
      display: block;
    }
    

    markup

    Email is required (first-child of message block is displayed) Invalid email format (error message hidden by default)

提交回复
热议问题