This is a fork of ampersand-form-view that has been altered to accept a template parameter, and to render input views within the template.
Here are the most important differences with the current ampersand-form-view
:
- Previously,
ampersand-form-view
did not actually inherit fromampersand-view
, it just implemented the conventions established for views in Ampersand. This version does inherit fromampersand-view
, so that we can make use ofrenderWithTemplate()
. - Because we inherit from
ampersand-view
and use theinitialize()
hook it provides, if you want to useinitialize()
in your own descendent of this view you need to call the base class'initialize
. You can do that like:
FormView = require('./ampersand-form-view')
FormView.extend({
initialize: function(){
FormView.prototype.initialize.call(this, arguments)
// ... Your initialization code here
}
})
- The format for passing in fields has changed. Instead of just passing a list of
ampersand-input-view
compatible views, you now pass a little object with a view and with a hook. The view gets rendered under the element in your template with the hook. You can use strings or functions as templates as usual, letting you separate out the overall design of your form from that of your inputs.
FormView = require('./ampersand-form-view')
FormView.extend({
template: "<div data-hook='my-excellent-input'></div>",
fields: [
hook: 'my-excellent-input',
field_view: new InputView({
// ...
})
]
})
- The original form view had an 'autoappend' setting. This is gone.
- It's not on NPM yet.
- It might be full of bugs, because I'm pretty new to Ampersand!
- Test more
- Integrate this with mainline Ampersand? It would be nice if we could roll the
hook
property intoampersand-input-view
. - I only realized that subviews exist recently, should this take advantage of that?
Alterations by PatrickKing Created by @HenrikJoreteg
MIT