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
Issue 96 #195
Issue 96 #195
Conversation
Thanks for taking this on! Couple thoughts here:
|
add ViewContext#form method that passes the scoped ViewCollection and context to Form. add Form#create and Form#update methods for manipulating forms.
Thanks for the feedback. Could you take a look at the spec to see if they are okay? Do we need more than these for now? |
module Presenter | ||
class Form | ||
|
||
attr_reader :form_view, :context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename form_view
to view
. It's already scoped within the form, so it seems redundant.
Ah, I love this. But I think you could write your example like this: data = { id: 1, name: 'a', images: [{ id: 1, name: 'b' }, { id: 2, name: 'c' }] }
view.form(:album).update(data) |view|
view.scope(:image).apply(data[:images]) do |fields, image|
fields.prop(:name).attrs.name = "album[images][#{image[:id]}[name]"
end
end |
Ok so just to be on the same page (since in the last iteration, I removed Because looking at your updated example, it seems that you want the method to simply yield the view to the block. |
That's a good point. For consistency, we should instance_exec when |
Blocks passed to Form#create and Form#update with be evaluated in the Form#view context if the block has an arity of 1. Otherwise, the view and data are yielded to the block.
Looks good to me! @jphager2: anything else you'd like to do or ask before I merge? |
I'm happy with it. |
Thanks :) |
This is a work in progress. (also see the TODOs)
This provides the api for managing forms.
View#form
is simply a alias forView#scope
and#create
and#update
(for bothView
andViewCollection
) uses bind to preform the normal data binding, then adds the specific form data, then passes the view to the block passed by the caller.