The code is slightly complicated, but let's say that's an advanced use. At least it seems possible!
But in practice there are three cases to cover:
If the behavior is on a regular element/value, e.g. <input value.bind="x & validate"> then binding.targetis the input element.
If the behavior is on a custom element, e.g. <my-input value.bind="x & validate">, then binding.target is the custom element ViewModel. At least, using this we can find out its controller in the enclosing view, which leads us to its element (given it's not @containerless).
If the behavior is on a custom attribute, e.g. <input my-value.bind="x & validate"> then binding.target is the custom attribute ViewModel. And there we're stuck. We can grab its controller but there is no link to its element.
I have no opinion how this could/should be fixed. Maybe an addition to binding or is that too costly? Otherwise an addition to the attribute controller?
Issue: it is impossible to get at the parent element from a binding behavior, if the behavior is used inside a custom attribute.
Context: I have built a validation component. It makes use of a binding behavior, which wants to grab the element, in a fashion that is exactly the same as this one from
aurelia-validation
: https://github.com/aurelia/validation/blob/master/src/validate-binding-behavior.js#L18-L31The code is slightly complicated, but let's say that's an advanced use. At least it seems possible!
But in practice there are three cases to cover:
<input value.bind="x & validate">
thenbinding.target
is the input element.<my-input value.bind="x & validate">
, thenbinding.target
is the custom element ViewModel. At least, using this we can find out its controller in the enclosing view, which leads us to its element (given it's not@containerless
).<input my-value.bind="x & validate">
thenbinding.target
is the custom attribute ViewModel. And there we're stuck. We can grab its controller but there is no link to its element.I have no opinion how this could/should be fixed. Maybe an addition to
binding
or is that too costly? Otherwise an addition to the attribute controller?