Inertia onSuccess and onError event not working in react
function handleSubmit(e){
e.preventDefault()
Inertia.put('user/password', {
_method: 'put',
current_password: abc,
password: ijk,
password_confirmation: xyz,
preserveScroll: true,
onSuccess: () => {
// currentPasswordRef.current.value = ''
// passwordRef.current.value = ''
// passwordConfimationRef.current.value = ''
console.log('success')
},
onError: () =>{
if(errors.updatePassword.current_password){
//currentPasswordRef.current.clear();
currentPasswordRef.current.focus();
}
if(errors.updatePassword.password){
// passwordRef.current.clear();
passwordRef.current.focus();
// passwordConfimationRef.current.clear();
passwordConfimationRef.current.focus()
}
}
})
}
I have fixed it, you are not supposed to mix the the data object and the options object together
Inertia.put('user/password', {
_method: 'put',
current_password: abc,
password: ijk,
password_confirmation: xyz,
preserveScroll: true,
},{
onSuccess: () => {
console.log('success')
}
});
Please or to participate in this conversation.