optimistex / ngx-select-ex

Angular based replacement for select boxes
https://optimistex.github.io/ngx-select-ex/
MIT License
111 stars 42 forks source link

Prevent text from clearing on a single select #35

Open perrosen opened 6 years ago

perrosen commented 6 years ago

Is there a way to prevent input text from being cleared on blur on a single select when user blurs without selecting an option? I have a case where I the search is being used to fetch results from the backend but the user should still have the possibility of manually adding the text using a button outside of component. Currently the blur/close seems to clear the input value.

Looking at the code I'm not sure where this is being cleared. Saw in the last release you added an option to clear the text for multiple select. Maybe another option can be set here to prevent clearing of input on single selects?

perrosen commented 6 years ago

For now I solved it by binding the input value to the placeholder element. Would be nice with an option for this instead of my little hack :)

optimistex commented 6 years ago

Looking at the code I'm not sure where this is being cleared.

You don't find it because I don't clear the input. It is a side effect of *ngIf directive. The input removes and puts back by *ngIf.

To solve your issue I think to change the *ngIf with [hidden] and add some logic for controlling to clear/NOclear the input.

Accepted as an enhancement to a next release.

perrosen commented 6 years ago

Yeah noticed its the actual input element being removed on blur which is why the text disappears.

Think the logic (at least for my use case) is that if input has content and nothing is selected then on blur the input shouldn't be hidden at all. A behaviour like this should maybe be controlled via a setting as to not break others implementation. But this would be super useful I think since you could make use of the component as an input field combined with a select 👍

perrosen commented 6 years ago

Also, thanks for the quick response. By far the best custom select for angular2 I have come across so far. Most are half broken or wrappers of select2 with jquery dependencies!

jackiewang5566 commented 6 years ago

Is this enhancement included in the new release?