[英]How to disable input fields conditionally in Vuejs
<input:type="passwordFieldType" v-model="user.password" id="password" name="password" class="input-section-three":class="{ 'is-invalid': submitted && $v.user.password.$error }" placeholder="Enter new password":maxlength="maxpassword" v-on:keypress="isPassword($event)" /> <input:type="passwordFieldTypetwo" v-model="user.confirmPassword" id="confirmPassword" name="confirmPassword" class="input-section-three":class="{ 'is-invalid': submitted && $v.user.confirmPassword.$error, }" placeholder="Confirm password":maxlength="maxconfirmpassword" v-on:keypress="isconfirmPassword($event)" />
I have two input fields like password and confirm password.我有两个输入字段,例如密码和确认密码。 where i am trying to disable confirm password field, untill user enter some content in password field.
我试图禁用确认密码字段,直到用户在密码字段中输入一些内容。 Can we do anything with v-bind:disabled="newPassword.length === 0? true: false" to get resolved.
我们可以用 v-bind:disabled="newPassword.length === 0? true: false" 做任何事情来解决。
If you simply need to lock the second field until the user types anything in the first one, try using the disabled
attribute on the second input:如果您只需要锁定第二个字段,直到用户在第一个字段中键入任何内容,请尝试在第二个输入上使用
disabled
属性:
<input
:disabled="!user.password"
...
>
This will set the disabled
attribute as long as the value of user.password
is falsy (eg. empty string).只要
user.password
的值是假的(例如空字符串),这将设置disabled
属性。
You can set either the :disabled="!newPassword"
or :read-only="!newPassword"
properties on the field.您可以在该字段上设置
:disabled="!newPassword"
或:read-only="!newPassword"
属性。
Either one should achieve the desired outcome, and then in your css if you need to apply any specific styles to the field you can use #confirmPassword::disabled {}
or #confirmPassword::read-only {}
任何一个都应该达到预期的结果,然后在您的 css 中,如果您需要将任何特定的 styles 应用于您可以使用
#confirmPassword::disabled {}
或#confirmPassword::read-only {}
的字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.