Skip to content

Setting Vee-Validate initial value from API #3744

Discussion options

You must be logged in to vote

You should use resetForm to assign initial values:

const { handleSubmit, errors, meta, resetForm } = useForm({
  // ....
});

onMounted(async () => {
  const api = useApi()
  const { data } = (await api.get(`/companies/${store.currentCompany.id}`));

  resetForm({ values: data });
})

resetForm does two things:

  • Sets the current form values
  • Sets the initial form values

Which means dirty would be false since the initial values match the current ones.

Replies: 3 comments 10 replies

Comment options

You must be logged in to vote
9 replies
@sschneider-ihre-pvs
Comment options

@logaretm
Comment options

@sschneider-ihre-pvs
Comment options

@sschneider-ihre-pvs
Comment options

@sschneider-ihre-pvs
Comment options

Answer selected by prochazka-storymkrs
Comment options

You must be logged in to vote
1 reply
@1nusah
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants