首页 > 解决方案 > 验证并在页面上显示所有错误并在条件满足时删除错误

问题描述

我想显示我在 Aurelia 验证中应用的所有错误消息。例如,如果用户单击密码输入框,那么所有相关的错误消息都应在用户满足所需条件时逐步突出显示/显示和隐藏/删除错误。我显示你是我的模特。

"newpassword":{
        "name": "newpassword",
        "value": "",
        "rules": [
          {
            "type": "isValidRegExp",
            "args": [/(?=.*[a-z])/],
           "msg" : "Password must contain at least 1 lowercase alphabetical character."
          },
          {
            "type": "isValidRegExp",
            "args": [/(?=.*[A-Z])/],
            "msg" : "Password must contain at least 1 uppercase alphabetical character."
          },
          {
            "type": "isValidRegExp",
            "args": [/(?=.*[0-9])/],
            "msg" : "Password must contain at least 1 numeric character."
          },
          {
            "type": "isValidRegExp",
            "args": [/(?=.[!@#\$%\^&])/],
           "msg" : "Password must contain at least 1 special character."
          },

如果用户进入密码字段,则应向用户显示模型中显示的 4 条错误消息

1- Password must contain at least 1 lowercase alphabetical character.
2- Password must contain at least 1 uppercase alphabetical character.
3- Password must contain at least 1 numeric character.
4- Password must contain at least 1 special character.

那么如果用户满足选项 1 那么选项 1 错误应该是隐藏/删除等等。

目前同时显示 1 条错误消息。

标签: javascriptvalidationaurelia

解决方案


推荐阅读