Vue Stepper Component Review
March 8, 2025 ยท AI Conversations
### 1. **Check if VeeValidate is Installed**
Run the following command in your project root:
yarn list vee-validate
or if using npm:
npm list vee-validate
If it's not installed, install it using:
yarn add vee-validate
or
npm install vee-validate
### 2. **Check the Import Path**
Ensure you're importing `vee-validate` correctly in `RegisterView.vue`.
For Vue 3, the correct import should be:
import { useForm, useField } from "vee-validate";
If you're using an older version, check the documentation for any breaking changes.
### 3. **Restart Vite Server**
After installing the package, restart the Vite development server:
yarn dev
or
npm run dev
### 4. **Check for Dependency Issues**
If you still face the issue, try deleting `node_modules` and reinstalling dependencies:
rm -rf node_modules yarn.lock package-lock.json
yarn install
or
rm -rf node_modules package-lock.json
npm install
Let me know if the issue persists! ๐
### Example:
<template>
<v-container>
<v-text-field
v-model="password"
:type="showPassword ? 'text' : 'password'"
label="Password"
variant="outlined"
prepend-inner-icon="mdi-lock"
:append-inner-icon="showPassword ? 'mdi-eye-off' : 'mdi-eye'"
@click:append-inner="showPassword = !showPassword"
></v-text-field>
</v-container>
</template>
<script setup>
import { ref } from "vue";
const password = ref("");
const showPassword = ref(false);
</script>
### Explanation:
– `v-model="password"`: Binds the input value to the `password` variable.
– `type="password"`: Initially hides the password.
– `:type="showPassword ? 'text' : 'password'"`: Toggles between password and text.
– `prepend-inner-icon="mdi-lock"`: Adds a lock icon inside the field.
– `:append-inner-icon="showPassword ? 'mdi-eye-off' : 'mdi-eye'"`: Adds an eye icon to toggle visibility.
– `@click:append-inner="showPassword = !showPassword"`: Toggles password visibility on clicking the eye icon.
Let me know if you need any modifications! ๐
### ๐ **Vuetify Password & Confirm Password with Validation**
<template>
<v-container>
<v-form @submit.prevent="onSubmit">
<!-- Password Field -->
<v-text-field
v-model="password"
:type="showPassword ? 'text' : 'password'"
label="Password"
variant="outlined"
prepend-inner-icon="mdi-lock"
:append-inner-icon="showPassword ? 'mdi-eye-off' : 'mdi-eye'"
@click:append-inner="showPassword = !showPassword"
:error-messages="passwordError"
></v-text-field>
<!-- Confirm Password Field -->
<v-text-field
v-model="confirmPassword"
:type="showConfirmPassword ? 'text' : 'password'"
label="Confirm Password"
variant="outlined"
prepend-inner-icon="mdi-lock-check"
:append-inner-icon="showConfirmPassword ? 'mdi-eye-off' : 'mdi-eye'"
@click:append-inner="showConfirmPassword = !showConfirmPassword"
:error-messages="confirmPasswordError"
></v-text-field>
<!-- Submit Button -->
<v-btn type="submit" color="primary" block>Register</v-btn>
</v-form>
</v-container>
</template>
<script setup>
import { ref, computed } from "vue";
import * as yup from "yup";
const password = ref("");
const confirmPassword = ref("");
const showPassword = ref(false);
const showConfirmPassword = ref(false);
// Define validation schema
const schema = yup.object({
password: yup.string().min(6, "Password must be at least 6 characters").required("Password is required"),
confirmPassword: yup.string()
.oneOf([password.value], "Passwords must match")
.required("Confirm Password is required"),
});
// Computed validation errors
const passwordError = computed(() => {
try {
schema.validateSyncAt("password", { password: password.value });
return "";
} catch (error) {
return error.message;
}
});
const confirmPasswordError = computed(() => {
try {
schema.validateSyncAt("confirmPassword", { confirmPassword: confirmPassword.value, password: password.value });
return "";
} catch (error) {
return error.message;
}
});
// Form submission
const onSubmit = () => {
try {
schema.validateSync({ password: password.value, confirmPassword: confirmPassword.value });
alert("Form submitted successfully!");
} catch (error) {
console.error(error.message);
}
};
</script>
### ๐ฅ Features:
โ
Password & Confirm Password fields
โ
Show/hide toggle for password visibility
โ
Validations using `yup` (minimum 6 characters, required, and match confirmation)
โ
Error messages displayed under fields
This ensures that the user enters a valid password and that both fields match before submitting. Let me know if you need further customizations! ๐