Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(typeahead): inside a form causes issues #92

Closed
ronzeidman opened this issue Jan 22, 2016 · 14 comments
Closed

chore(typeahead): inside a form causes issues #92

ronzeidman opened this issue Jan 22, 2016 · 14 comments

Comments

@ronzeidman
Copy link

Hi,
I've encountered several issues trying to put Typeahead inside a form.

  1. ngControl doesn't work (throws a "No provider for NgModel! (Typeahead -> NgModel)" exception)
  2. Typeahead inside a form causes submit on enter, form submission should be prevented on enter when the choices are presented (since you just want to select the choice).
  3. "autocomplete" should be "off" by default.
  4. Also choices should automatically close on blur (This also happens on a non-form typeahead)
  5. I think "TAB" should also choose the typeahead choice.
@valorkin
Copy link
Member

  1. ngControl doesn't work (throws a "No provider for NgModel! (Typeahead -> NgModel)" exception)

it means you should have ngModel on same element with typeahead directive

  1. Typeahead inside a form causes submit on enter, form submission should be prevented on enter
    when the choices are presented (since you just want to select the choice).

can you create a plunker for it? it sounds critical

  1. "autocomplete" should be "off" by default.

will have to check it

  1. Also choices should automatically close on blur (This also happens on a non-form typeahead)
  2. I think "TAB" should also choose the typeahead choice.

may be on lostfocus, but yes

@ronzeidman
Copy link
Author

  1. it happens also when ngModel is present.

is there a CDN or a base plunkr for ng2-bootstrap?

@ronzeidman
Copy link
Author

I've uploaded a test in my github: https://github.com/ronzeidman/open-ng2-tests
It shows the form submission.
In addition if you just add 'ngControl="something"' (not remove anything) to the input an exception will be thrown.

I'm always amazed by your fast responses!

@valorkin
Copy link
Member

is there a CDN or a base plunkr for ng2-bootstrap?

If I will be lucky, I will land system.js bundling with TS 1.8 on this weekends
Thanks for repo, I will take a look :)

In addition if you just add 'ngControl="something"' (not remove anything) to the input an exception will be thrown.

hm

I'm always amazed by your fast responses!

do my best :)

@valorkin valorkin changed the title Typeahead inside a form causes issues chore(typeahead): inside a form causes issues Jan 28, 2016
@nrehm
Copy link

nrehm commented Mar 18, 2016

Anyone found a solution to this problem?
Would like to use it inside a form and cant really track down why its breaking when you have ngModel and ngControl on the same Input.

@nrehm
Copy link

nrehm commented Mar 20, 2016

Digged into it a little bit and copy / changed something from the ngModel directive and added it to typeahead.directive.ts

const formControlBinding = 
         CONST_EXPR(new Provider(NgModel, {useExisting: forwardRef(() => NgControl)}));

and inside the directive decorator

bindings: [formControlBinding]

It seem to works now in both cases but my angular2 foo is to weak after just 1 week.
Im not sure what is happening and why its really working now but it feels like to be on the right side of the fence

@slintes
Copy link
Contributor

slintes commented Mar 31, 2016

I came across the same issue (1) today, thanks a lot for the fix / workaround(?) @nrehm, works for me too! You should create PR for it :)

First I thought I came across this issue: angular/angular#6374, but I'm not sure if that is related, my knowledge of the Angular2 internals is also very limited.

@ronzeidman: you might be happy to hear that your point 4 was merged yesterday :) #351

@ronzeidman
Copy link
Author

@slintes :) happy to hear.
Looking forward to try and integrate this again.

@Toktik
Copy link

Toktik commented Apr 8, 2016

Workaround:

Adding this to parent component (which includes typeahead) fixes the No provider for NgModel! (Typeahead -> NgModel)" exception) exception

providers: [NgModel]

@valorkin
Copy link
Member

valorkin commented Apr 8, 2016

@Toktik this is awesome idea! And the simplest one!

@slintes
Copy link
Contributor

slintes commented Apr 11, 2016

Mh, the workaround of @Toktik didn't work for me. I didn't get the "no provider..." error anymore, but another error as soon as I start typing (model in this.cd.model in typeahead.directive.ts.onChange() was undefined)... no clue why, but with the fix of @nrehm it works.
Besides that for me it does feel wrong that I have to provide NgModel in the parent component for getting this to work.
I created a PR with the solution of @nrehm: #396

@Dinistro
Copy link
Contributor

Dinistro commented Aug 3, 2016

This should be fixed in the newest version

@Dinistro Dinistro closed this as completed Aug 3, 2016
@slintes
Copy link
Contributor

slintes commented Aug 29, 2016

just updated to RC 5 and new FormsModule, no problems anymore, thanks!

@dietergeerts
Copy link

Using v1.3.2, but the autocomplete is still not off. Can this be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants