Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Make it optional to initiate data #85

Closed
perifer opened this issue Feb 13, 2020 · 7 comments
Closed

Make it optional to initiate data #85

perifer opened this issue Feb 13, 2020 · 7 comments

Comments

@perifer
Copy link

perifer commented Feb 13, 2020

Hi, and thanks for a great lib!

I have come across a use-case where it would be useful to not have to initiate all properties up front. It's a create-form with lots of form fields, where having to initiate all of them would be cumbersome. This is Laravel and what we would like to do is to pass some initial values by serializing a new model, but by doing that the attributes that are not set will not be serialized.

The use-case is somewhat similar to this issue in Vue where they eventually changed a behavior in Vue 2: vuejs/vue#5932 (comment)

When looking through the code it struck me that you are doing some work in guardAgainstReservedFieldName() to allow setting properties directly on the Form class, so my understanding is that is not as simple as moving the form data to separate object on the Form class.

@perifer perifer changed the title Make it optional to declare initial data Make it optional to initiate data Feb 13, 2020
@perifer
Copy link
Author

perifer commented Feb 13, 2020

I just realised that the issue I referenced has the answer to why the data is stored directly on the Form class - Vue only allows reactive properties that doesn’t exist one level deep.

@sebastiandedeyne
Copy link
Member

Yeah, I'm afraid this would lead to reactivity issues, so gonna have to keep it as is.

@perifer
Copy link
Author

perifer commented Mar 24, 2020

We managed to find a good enough solution for our use-case. The solution with guardAgainstReservedFieldName() feel a bit nonoptimal though. It's not that far fetched that a form could have fields with names like "data", "delete" etc.

@sebastiandedeyne
Copy link
Member

If I'd rewrite this package, I'd probably put all values under form.values to get around this problem. But that would completely change the API, so keeping this as is for now :)

@perifer
Copy link
Author

perifer commented Mar 24, 2020

But wouldn't that break the reactivity of those values, since they would not be "one level deep" anymore?

I was thinking one option was to move everything else, and keep the data on the form object. That would still break the API though.

@sebastiandedeyne
Copy link
Member

sebastiandedeyne commented Mar 24, 2020 via email

@perifer
Copy link
Author

perifer commented Mar 24, 2020

Yeah, definately worth looking into.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants