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

Is there a way to make a request whenever I want? #23

Open
AndreiaMatiasSilva opened this issue May 18, 2017 · 9 comments
Open

Is there a way to make a request whenever I want? #23

AndreiaMatiasSilva opened this issue May 18, 2017 · 9 comments

Comments

@AndreiaMatiasSilva
Copy link

I'm trying to make a request using
this.$refs.autocomplete.getData(string);

but the component does not react.

@AndreiaMatiasSilva AndreiaMatiasSilva changed the title Is there a way to make a request whenever we want? Is there a way to make a request whenever I want? May 22, 2017
@BosNaufal
Copy link
Owner

Hi @AndreiaMatiasSilva,
I know it's too late to discuss it. But, would you like to tell me the case when do you want to make a request outside of the exsisting event from autocomplete?

@MingJen
Copy link

MingJen commented Aug 22, 2017

I have a case.

[
'B-10',
'B-10-1',
'B-10-2,
]

When I key in B-10 and select it.
I want to show B-10-1 and B-10-2 again.

So I want to getData again when onSelect.
but i don't know how to do that.

@timberkeley
Copy link

I had a similar issue and implemented is follows:

Added ref="autocomplete" to auto complete

  onSelect (obj) {
     this.$nextTick(() => {
       this.$refs.autocomplete.setValue(obj.Text)
       this.$refs.autocomplete.showList = true
       this.$refs.autocomplete.getData(obj.Text)
    })
}

Not pretty but it seems to work for me.

@MingJen
Copy link

MingJen commented Aug 28, 2017

Hi, @timberkeley

Thanks for your help.

I try to use your solution, but only works when use keyboard. Can't use on mouse click.

Finally, I use setTimeout replace nextTick, but I really need more smooth solution.

@BosNaufal
Copy link
Owner

Hi @MingJen,
would you like to explain to me more clearly? Do you want to make the list keep showing even one of them has been selected?

@MingJen
Copy link

MingJen commented Aug 29, 2017

Hi @BosNaufal,

I record a gif
ezgif-2-e5027e8b24

I want to use the selected result to query again.

onSelect(selectInfo)
{
    let refName = selectInfo.key;
    setTimeout(() => {
        let e = {
            target: {value: selectInfo.name}
        };
        this.$refs[refName][0].handleInput(e);
    }, 350);
}

@BosNaufal
Copy link
Owner

Hi @MingJen,
I think, we just need to make a method to open the data list of autocomplete, right?

so the flow will be:
on selected -> change the props options of autocomplete -> open it
-> on selected -> change the props options of autocomplete -> open it

@timberkeley
Copy link

It would also be nice to use the 'value' props / emit 'input' to control the search term. I was going to do a pull request for this. That way you could just use v-model to control what you are searching for and also pick up the value typed if you want to use it directly, for a full search rather than a suggestion for example.

I was going to do a pull request for this, time permitting.

timberkeley pushed a commit to TheBookPeople/vue2-autocomplete that referenced this issue Aug 30, 2017
@timberkeley
Copy link

Hi @BosNaufal & @MingJen,
I have just opened a pull request that I think implements this feature.

You can reference a data value using:

v-model="searchText"

and then simply use:

this.searchText = newText

In the onSelect callback and the component should re-search for the new text.

Please check it out to see if the solution is acceptable.

Cheers, Tim

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

4 participants