Reputation: 1952
I created a PasswordFields.vue file.
<template>
<div>
<el-form-item label="Mot de passe"
prop="password"
:error="this.registerForm.errors.get('password')"
required
:rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
<el-input type="password" name="password" id="password" v-model="this.registerForm.password">
</el-input>
</el-form-item>
<!-- confirm password -->
<el-form-item label="Confirmation du mot de passe"
prop="password_confirmation"
:error="this.registerForm.errors.get('password_confirmation')"
required
:rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
<el-input type="password" name="password_confirmation" id="password_confirmation" v-model="this.registerForm.password_confirmation">
</el-input>
</el-form-item>
</div>
</template>
Whenever I call my component in my Blade view, like this:
<password-fields></password-fields>
I have an error that says the property or method method is not defined on the instance but referenced during render.
I tried this, but it still does not work
<password-fields registerForm="registerForm"></password-fields>
Can you help me ? How to pass the value to my component? thank you very much
EDIT (the end of my component)
<script>
export default {
data() {
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('Please input the password'));
} else {
if (this.registerForm.password_confirmation !== '') {
this.$refs.registerForm.validateField('password_confirmation');
}
callback();
}
};
var validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error('Please input the password again'));
} else if (value !== this.registerForm.password) {
callback(new Error('Two inputs don\'t match!'));
} else {
callback();
}
};
return {
rulesPass: {
pass: [
{ validator: validatePass, trigger: 'blur' }
],
checkPass: [
{ validator: validatePass2, trigger: 'blur' }
]
}
}
}
}
Upvotes: 0
Views: 1692
Reputation: 393
this
in the templateprops
in componentExample Component:
<template>
<div>
<el-form-item label="Mot de passe"
prop="password"
:error="registerForm.errors.get('password')"
required
:rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
<el-input type="password" name="password" id="password" v-model="registerForm.password">
</el-input>
</el-form-item>
<!-- confirm password -->
<el-form-item label="Confirmation du mot de passe"
prop="password_confirmation"
:error="registerForm.errors.get('password_confirmation')"
required
:rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
<el-input type="password" name="password_confirmation" id="password_confirmation" v-model="registerForm.password_confirmation">
</el-input>
</el-form-item>
</div>
</template>
<script>
export default {
data() {
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('Please input the password'));
} else {
if (this.registerForm.password_confirmation !== '') {
this.$refs.registerForm.validateField('password_confirmation');
}
callback();
}
};
var validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error('Please input the password again'));
} else if (value !== this.registerForm.password) {
callback(new Error('Two inputs don\'t match!'));
} else {
callback();
}
};
return {
rulesPass: {
pass: [
{ validator: validatePass, trigger: 'blur' }
],
checkPass: [
{ validator: validatePass2, trigger: 'blur' }
]
}
}
}
}
props: ['registerForm'],
}
</script>
Upvotes: 1