Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kachi_dk's avatar

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()
        }
      }
    })
  }
0 likes
1 reply
kachi_dk's avatar
kachi_dk
OP
Best Answer
Level 1

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')
      }
});
3 likes

Please or to participate in this conversation.