1

I'm not sure what the right approach here is. I am setting up a simple form. I need a couple of standard HTML input fields and a couple of select inputs. The data is coming from a couple of different sources and I would like to present the models and collections, with their data to the view like so:

Controller:

var registerView = new registrationView.RegistrationForm({  
    model: userModel,  
    model2: departmentCollection  
});
myApp.SomeRegion.show(registerView);

Can I do this? Or do I need to split the form into separate regions, all with their own model or collection. If so, how do I call the model data in the template. I have not been able to make it work so far. I cannot find any examples of a form with mixed fields coming from different models and collections,

Many thanks

Wittner

Wittner
  • 583
  • 5
  • 21

1 Answers1

0

You can do it using a composite view:

var registrationView.RegistrationForm = Marionette.CompositeView({
   // ...
});

var my View = new registrationView.RegistrationForm({  
    model: userModel,  
    collection: departmentCollection  
});

See https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.compositeview.md and https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.collectionview.md (a composite view inherits behavior from a collection view).

David Sulc
  • 25,946
  • 3
  • 52
  • 54
  • Thanks David. I learned as much from you excellent book :-) However, I didn't know if that was 'overkill' or the best way to tackle this. So, if I have a form with several select inputs, a correct pattern would be to divide the page up (perhaps with a layout) and use different regions with separate views, each with their respective models/collections to create the single form? – Wittner Feb 07 '14 at 10:20
  • That's my preference: it's a little more to cde, but simpler to maintain. But you can also do it in a single view if you prefer. It bascially comes down to preference... – David Sulc Feb 07 '14 at 10:24