简体   繁体   English

使用Material Design Lite错误确认密码验证

[英]Confirm password validation using material design lite errors

I am currently creating a web page using Google's material design lite and I hit a stumbling block on the necessary changes needed to change the confirm password textbox to invalid when the passwords to not match. 我目前正在使用Google的Material Design Lite创建网页,并且在密码不匹配时将确认密码文本框更改为无效所需的必要更改上遇到了绊脚石。 Thus generating an error with the style mdl-textfield__error style if the passwords do not match. 如果密码不匹配,则会生成样式为mdl-textfield__error的错误。

How could I achieve this using MDL? 如何使用MDL做到这一点?

<tr>
    <td>
        <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
            <form:input path="password" type="password" class="mdl-textfield__input" id="password" required="true" pattern=""  />
            <label class="mdl-textfield__label" for="email">Password</label>
            <span class="mdl-textfield__error"> Input must not be empty</span>
        </div>
    </td>
</tr>
<tr>
    <td>
        <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
            <input path="password" type="password" class="mdl-textfield__input" id="password" required pattern=""  />
            <label class="mdl-textfield__label" for="email">Confirm Password</label>
            <span class="mdl-textfield__error"> Input must be equal to password</span>
        </div>
    </td>
</tr>

If your question is regarding how to apply the style dynamically,give the two password fields different ids say password1 and passoword2 and use the following code in jquery to give the styling. 如果您的问题是关于如何动态应用样式的,请给两个密码字段赋予不同的ID,例如password1和passoword2,并在jquery中使用以下代码进行样式设置。

$("#password2").parent().addClass('is-invalid');

Also removing the invalid styling would involve the use of the removeClass function instead. 同样,删除无效的样式将涉及使用removeClass函数。

I got the idea from comment of b2550 at this url https://github.com/google/material-design-lite/issues/1502 我从b2550的评论中获得了这个想法,网址为https://github.com/google/material-design-lite/issues/1502

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM