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

Hash + Model Example? #34

Closed
GantMan opened this issue Aug 24, 2012 · 5 comments
Closed

Hash + Model Example? #34

GantMan opened this issue Aug 24, 2012 · 5 comments

Comments

@GantMan
Copy link
Contributor

GantMan commented Aug 24, 2012

Formotion is awesome.

It's great that a form can be initialized via hash or DSL, but it's somewhat unclear to me how to initialize with a hash that ties into a model without a submit button.

I've looked at the examples:
EXAMPLE FormModel
Uses the DSL to tightly couple the form data to the model

EXAMPLE KitchenSink
Uses the hash, but the data does not persist: Looks intended to be submitted to a webservice.

Of course what I"m looking for is to get the hash to tie in comfortable with the model (the mix of the 2). I don't want to break standard and use a "Submit" button. Since no settings page operates like that.

From what I can tell, you can initialize initWithForm XOR initWithModel. What I truly want is to initWithForm (so I can use the hash cleanliness) and then set a model. Maybe even a model per section!? if I want to be tidy.

I can't imagine I'm the only one with this requirement. Perhaps the formable should have the ability to set? Instead of just init?
I saw the formable code essentially observes change. I could write my own, but it seems that should be part of the formotion core right?

I feel like I've got a handle on the problem, but not so much on the solution. Is the solution just something I'm missing, or is it actually missing due to the incipient nature of the project?

@clayallsopp
Copy link
Owner

Hmm not totally clear on what you're looking for =\ Maybe an example of the API you're looking for? I know you tried to explain it, but it's not clicking with me right now

The submit button isn't required or even added by default; in a FormController or FormableController subclass, just set the submit callback and add a place where that's triggered:

def viewDidLoad
    super

    self.form.on_submit do
       self.submit
    end

    # Custom UI for submitting a form
    self.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemSave, target:self, action:'submit')
  end

  def submit
    data = self.form.render

    # do something with data
  end

@GantMan
Copy link
Contributor Author

GantMan commented Aug 26, 2012

Gotcha, I appreciate your help. I'll just simplify what I was looking for (the root of this) and hopefully you can see what I was I'm saying.

Simply put, example FormModel data persists, and example KitchenSink data doesn't.

If there was a property on KitchenSink, when flipped would make the data persist, I would have what I wanted. Does that help?

FormModel, is a model automagically building a view. I'm looking for formotion's easlily buildable views (KitchenSink) to automagically build a model. Maybe I'm off in thinking that's the purpose of the methods of building provided.

@GantMan
Copy link
Contributor Author

GantMan commented Aug 27, 2012

It appears I'm completely wrong. I could have SWORN that FormModel example maintained the data for you. I guess the app was still live in the background. My mistake, please disregard most of what I said.

I still think it would be great if formotion was able to maintain state for you, but everything else above is just flat wrong.

@GantMan GantMan closed this as completed Aug 27, 2012
@clayallsopp
Copy link
Owner

Ahh okay, didn't realize that's what you meant by persist. Yeah in the future that could be neat, especially for models. Pull requests are always welcome!

@GantMan
Copy link
Contributor Author

GantMan commented Aug 28, 2012

Soon as I implement it in my current project, I'll def make an effort to add it with a pull request. Thanks for listening to my confusion :)

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

2 participants