Skip to content

Commit bbfe7a5

Browse files
committed
fix: Multiple inputs use id=password on account settings
Fixes #229
1 parent 8057146 commit bbfe7a5

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

resources/js/components/forms/ChangePassword.vue

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ import SettingsHeader from '@/components/settings/SettingsHeader.vue';
1212
import SettingsCard from '@/components/cards/layout/SettingsCard.vue';
1313
import useForm from '@/composables/useForm';
1414
15+
// To avoid having duplicate inputs with the same id on the account settings page
16+
type ChangePasswordFormValues = {
17+
current_password: string;
18+
new_password: string;
19+
password_confirmation: string;
20+
};
21+
1522
const fields = reactive<FormField[]>([
1623
{
1724
name: 'current_password',
@@ -24,7 +31,7 @@ const fields = reactive<FormField[]>([
2431
max: 255,
2532
},
2633
{
27-
name: 'password',
34+
name: 'new_password',
2835
text: `New Password`,
2936
placeholder: `New Password`,
3037
autocomplete: 'new-password',
@@ -42,16 +49,24 @@ const fields = reactive<FormField[]>([
4249
},
4350
]);
4451
45-
const form = useForm<ChangePasswordRequest>({
52+
const form = useForm<ChangePasswordFormValues>({
4653
current_password: '',
47-
password: '',
54+
new_password: '',
4855
password_confirmation: '',
4956
});
5057
58+
const mapToChangePasswordRequest = (fields: ChangePasswordFormValues): ChangePasswordRequest => {
59+
return {
60+
current_password: fields.current_password,
61+
password: fields.new_password,
62+
password_confirmation: fields.password_confirmation,
63+
};
64+
};
65+
5166
const handleSubmit = async () => {
5267
form.submit(
5368
async (fields) => {
54-
return changePassword(fields);
69+
return changePassword(mapToChangePasswordRequest(fields));
5570
},
5671
{
5772
onSuccess: (response) => {
@@ -60,7 +75,7 @@ const handleSubmit = async () => {
6075
},
6176
onError: () => {
6277
if (form.errors.password) {
63-
form.reset('password', 'password_confirmation');
78+
form.reset('new_password', 'password_confirmation');
6479
return;
6580
}
6681

0 commit comments

Comments
 (0)