1

I've already got a directive what is implementing the ControlValueAccessor interface (directive's selector is input[type=date]) and I need to have another directive implementing ControlValueAccessor with selector input[type=date][datepicker] - let's call it the datepicker directive.

As you can see the selectors of those directives are covering each other and I'm getting following error when I'm using the datepicker directive:

ERROR Error: Uncaught (in promise): Error: More than one custom value accessor matches form control with unspecified name attribute

the error is thrown there: https://github.com/angular/angular/blob/5.2.x/packages/forms/src/directives/shared.ts#L206

so I've got an idea that maybe I could somehow tell angular to provide the datepicker directive when it is possible, but how to do that?

roomcayz
  • 2,334
  • 4
  • 17
  • 26

1 Answers1

2

Why not simply play with the selectors ?

The first would be

input[type=date]:not([datepicker])

And second one

input[type=date][datepicker]
  • wow, awesome idea, I'll use it for now, but I'm still curious if there is a way for providing control value accessors - at least built-in directives doesn't have such problems yet they selectors are covering each other as in my case – roomcayz May 15 '18 at 09:17
  • eg. DefaultValueAccessor (https://github.com/angular/angular/blob/5.2.x/packages/forms/src/directives/default_value_accessor.ts) - there is used the same trick only for `[type=checkbox]` but there is also other accessors eg. for number (https://github.com/angular/angular/blob/5.2.x/packages/forms/src/directives/number_value_accessor.ts) where such trick seems to be not necessary – roomcayz May 15 '18 at 09:22
  • Well I don't know about you, but I see the same selector logic that I've just provided to you in those two ! –  May 15 '18 at 09:24
  • not at all, that's true for `DefaultValueAccessor`, which is using `:not([type=checkbox])`, but at the same time it is not using the `:not([type=number])`, yet `NumberValueAccessor` exists, or am I missing something? – roomcayz May 15 '18 at 09:37
  • 1
    Oh my bad, i see what you mean. Sorry, I can't help you about that, I usually rely on the selectors to avoid conflicts ... –  May 15 '18 at 09:40