Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialize application form with resource attributes by default #105

Open
hiattp opened this issue Jan 17, 2019 · 4 comments
Open

initialize application form with resource attributes by default #105

hiattp opened this issue Jan 17, 2019 · 4 comments

Comments

@hiattp
Copy link
Contributor

hiattp commented Jan 17, 2019

Whenever I override the initialize method in ApplicationForm I use the resource attributes as the default params instead of {}. This provides more intuitive behavior because you can initialize the form object passing only the resource and the form object will behave (state-wise) as the object itself (default values are set to whatever the current resource values are). Otherwise you can pass a user into the form initializer and no params (e.g. on an edit action) and see no default values populating the form.

I suggest we do something more like this in the application form, but wanted to propose it as a question first in case I'm missing any obvious disadvantages here:

def initialize(resource = self.class.resource_class.new, params = resource.attributes)
  ...
end
@janklimo
Copy link
Contributor

It makes sense to me though I have no experience with this use case. @vvmarulin?

@hiattp
Copy link
Contributor Author

hiattp commented May 30, 2019

Once we get to the next phase of vmx we should just audit the custom form objects and see how often this pattern is used, that can be a heuristic for whether or not this will be a sensible default 👍

@hiattp hiattp self-assigned this May 30, 2019
@janklimo
Copy link
Contributor

janklimo commented Mar 3, 2020

@hiattp any new thoughts on this given that we have more experience with the subject now?

@hiattp
Copy link
Contributor Author

hiattp commented Mar 3, 2020

Yep, we actually made this change in VmX almost a year ago and it seems to be working well I think it is template-worthy at this point 👍

@hiattp hiattp removed the question label Mar 3, 2020
@hiattp hiattp removed their assignment Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants