inertia icon indicating copy to clipboard operation
inertia copied to clipboard

Form defaults not working

Open betaSavvy opened this issue 2 years ago • 1 comments

Versions:

  • @inertiajs/inertia version: 0.11.0
  • @inertiajs/inertia-vue3 version: 0.6.0

Describe the problem:

form.defaults() is not working.

Steps to reproduce:

In the page, I have a form like this

form = useForm({
  foo: '',
});

On page load, i call this function

const initForm = () => {
  form.foo = 'bar';

  // Set the form's current values as the new defaults
  form.defaults();
}

I setup a button to console.log the result of form.isDirty and it always return true. Did I misunderstand the usage of defaults? I have also tried it with the following:

// Update the default value of a single field
form.defaults('foo', 'bar');

// Update the default value of multiple fields
form.defaults({ 
  foo: 'bar',
});

betaSavvy avatar Jun 08 '22 03:06 betaSavvy

form.defaults() only updates the defaults, it leaves the current form intact. You'd have to call form.reset() after updating the defaults if you want to reset the current fields to the (new) defaults.

RobertBoes avatar Jun 08 '22 08:06 RobertBoes

I hope this changes with the 1.0.0 version because this makes no sense at all.

flavio-schoute avatar Dec 10 '22 10:12 flavio-schoute

I hope this changes with the 1.0.0 version because this makes no sense at all.

What does make sense here? Should form.defaults() also immediately reset the form data? What if you only want to update the defaults and not reset the form?

I'm not sure it will help in every situation, but last night I added an option to the form helper in the Vue adapters to allow providing an initialization callback that's automatically run when resetting a form. Check that out here: #1516

reinink avatar Apr 14 '23 11:04 reinink

Hey! Thanks so much for your interest in Inertia.js and for sharing this issue/suggestion.

In an attempt to get on top of the issues and pull requests on this project I am going through all the older issues and PRs and closing them, as there's a decent chance that they have since been resolved or are simply not relevant any longer. My hope is that with a "clean slate" me and the other project maintainers will be able to better keep on top of issues and PRs moving forward.

Of course there's a chance that this issue is still relevant, and if that's the case feel free to simply submit a new issue. The only thing I ask is that you please include a super minimal reproduction of the issue as a Git repo. This makes it much easier for us to reproduce things on our end and ultimately fix it.

Really not trying to be dismissive here, I just need to find a way to get this project back into a state that I am able to maintain it. Hope that makes sense! ❤️

reinink avatar Jul 28 '23 01:07 reinink