AmpersandJS / ampersand-input-view

A view module for intelligently rendering and validating input. Works well with ampersand-form-view.
MIT License
17 stars 19 forks source link

Enable usage of existing input #41

Closed cdaringe closed 9 years ago

cdaringe commented 9 years ago

Problem statement

If a form uses autoAppend: false, it assumes that I am already providing an element to the form. Indeed, on new InputView, I pass an el. However, that el is disregarded, and no bindings are wired up.

Solution

If an el is provided, set it, and call render immediately to wire the bindings/etc. Only renderWithTemplate if there is no el present.

HenrikJoreteg commented 9 years ago

So if you pass and el to the input view wouldn't you still want to render into that element with the template? The idea for this is that in many forms you don't want to just put all your inputs in a single container, so what you'd do in your HTML for the form is create whatever structure you're want it to have, but then having "placeholder" elements that you'd pass to the individual input views, that the input views would render themselves into. In that case, i'd want it to call renderWithTemplate even when having an el.

cdaringe commented 9 years ago

Indeed, it is designed for a container. The trouble originates in that I didn't want the rendered <input> to be a generic el that I know nothing about. I have additional events/bindings/etc for that <input>. If the template is predefined, it's cumbersome to set up a data-hook against the <input>. I suppose from an extended View I could simply reference this.input or do a query, but, I still cannot have custom attrs on a pre-defined <input>, which I think is worthy of supporting (i.e. let me use my own <input>).

Maybe I should just ask you to disregard this PR and look at my subsequent PR which is really is an alternate strategy. https://github.com/AmpersandJS/ampersand-input-view/pull/42/

HenrikJoreteg commented 9 years ago

closing in lieu of #42 as you suggested.