JavaScript
x
1
1
JavaScript
1
3
1
<button type="submit"
2
:disabled=" (user.password && !$v.user.password.valid) ||
3
(user.confirmPassword && !$v.user.confirmPassword.sameAsPassword)">sda </button>
JavaScript
1
1
1
With length i need to disable, untill user enterd equal characters in both fields. i need to check both field values.
Can i do this by using length?? if yes how can i check with above code.
Issue is at present it is checking only for, If entered password is matched with first character in confirm password field, it is proceeding.
Advertisement
Answer
I don’t know if i understood correctly but i think you can simply add && user.password.length>8
or since you are using vuelidate you can add this validation:
https://codepen.io/sibellek/pen/oNBPVbN
JavaScript
1
72
72
1
<div id="app">
2
<input
3
v-model="user.confirmPassword"
4
id="confirmPassword"
5
name="confirmPassword"
6
placeholder="Confirm password"
7
autocomplete="off"
8
:disabled="user.password.length < 8"
9
@change="disabledSubmit"
10
/>
11
12
13
<div
14
class="error-messages-pass"
15
>
16
17
<input
18
v-model="user.password"
19
id="password"
20
name="password"
21
value=""
22
placeholder="Enter new password"
23
autocomplete="off"
24
@change="disabledSubmit"
25
/>
26
</div>
27
<button type="submit"
28
:disabled="disableButton">sda </button>
29
</div>
30
31
32
new Vue({
33
el: "#app",
34
data: {
35
user: {
36
password: "",
37
confirmPassword: "",
38
},
39
disableButton: false,
40
},
41
validations: {
42
43
user: {
44
password: {
45
valid: function (value) {
46
const containsUppercase = /[A-Z]/.test(value)
47
const containsLowercase = /[a-z]/.test(value)
48
const containsNumber = /[0-9]/.test(value)
49
const containsSpecial = /[#?!@$%^&*-]/.test(value)
50
return containsUppercase && containsLowercase && containsNumber && containsSpecial
51
},
52
required, minLength: minLength(8), maxLength: maxLength(20)
53
},
54
confirmPassword: { required, sameAsPassword: (value, vm) =>
55
value === vm.password.substring(0, value.length) },
56
},
57
},
58
methods: {
59
disabledSubmit() {
60
this.$v.user.$touch();
61
this.disableButton = this.user.password.length<8 ||
62
this.$v.user.password.$error || this.user.password!==this.user.confirmPassword;
63
}
64
},
65
mounted() {
66
this.disabledSubmit();
67
}
68
})
69
70
71
72
and that way you can keep your code the same way