ember-bootstrap icon indicating copy to clipboard operation
ember-bootstrap copied to clipboard

Expose error, helpmessages and other components rendered by FormElement to the yielded hash

Open ohcibi opened this issue 7 years ago • 3 comments

Currently the error message component and helptext are both hardcoded to be below of the input field. Don't hardcode any component that should be rendered in a FormElement when there is a block template but expose everything in a hash like the control itself.

e.g.

{{#form.element ... as |el|}}
  {{el.control}}
  {{el.errors}}
  {{el.helpText}}
{{/form-element}}

ohcibi avatar Sep 29 '18 16:09 ohcibi

Thanks for the suggestion! But that alone won't be enough, because currently the form element already supports a block form, where the control is yielded (in case it has to be customized), but the other markup (errors, labels etc.) is nevertheless automatically rendered (which I think is a common use case).

So at least some kind of flag would be needed, to signal not to render the other things by default.

But I think the API for something like this needs to be fleshed out better. Maybe some other component than element which is yielded by form, that allows more customization?

Especially with Bootstrap 4 the possibilities to customize the form layout have increased. I am well aware that e-b is quite a bit limiting in that regard currently...

simonihmig avatar Sep 30 '18 19:09 simonihmig

I see your point. Maybe the layout-horizontal-vertical-thing is a bit overengineered.

I'd create sub components for everything thats inside a layout, i.e. label, errorComponent and helpTextComponent (and whats to come). In the element's template's non-block-form I'd simply use an if for horizontal vs vertical and then print the layouts template directly or even put the code inline. Then it is easy to yield the components in question to the element hash.

I don't know the reasoning behind the way you did the layout thing, so I might be missing something here.

ohcibi avatar Oct 01 '18 11:10 ohcibi

Named blocks, which are nowadays available in Ember, seems to be a great solution for this one: https://github.com/emberjs/rfcs/blob/master/text/0226-named-blocks.md

jelhan avatar Oct 25 '21 21:10 jelhan