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

bug: Searchbar cancel event is execute input function #6382

Closed
MatanYadaev opened this issue Apr 29, 2016 · 6 comments
Closed

bug: Searchbar cancel event is execute input function #6382

MatanYadaev opened this issue Apr 29, 2016 · 6 comments
Assignees
Milestone

Comments

@MatanYadaev
Copy link

MatanYadaev commented Apr 29, 2016

Type: bug

Ionic Version: 2.x

Platform: all

When there is no text in searchbar and you click on cancel button, the searchbar is execute the (input) function (input)="loadItems($event)".

It's should execute the function only if there is text in search and than clicking cancel.

Look here my example here:
https://drive.google.com/file/d/0B_2AM8ZhXhE9U3RGdEJtRF82Ujg/view

I wish you understood the problem...

@Ionitron Ionitron added the v2 label Apr 29, 2016
@jgw96
Copy link
Contributor

jgw96 commented Apr 29, 2016

Hello @MatanYed ! Thanks for opening an issue with us! I cant seem to see your example, it looks like the url is incorrect, would you mind reposting it?

@jgw96 jgw96 added the needs: reply the issue needs a response from the user label Apr 29, 2016
@MatanYadaev
Copy link
Author

@jgw96 oh, oops, i added it now.

@jgw96
Copy link
Contributor

jgw96 commented Apr 29, 2016

@MatanYed Thanks, i can see the example now. Would you be able to provide a minimal code example that i can use to reproduce this? Thanks

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label Apr 29, 2016
@MatanYadaev
Copy link
Author

@jgw96 Sure.

HTML:

<ion-toolbar class="slider" dark [class.closed]="!searchbarVisible">
    <ion-searchbar [(ngModel)]="searchQuery" (input)="loadSearchedPosts($event)"></ion-searchbar>
</ion-toolbar>

Typescript:

loadSearchedPosts(searchbar?) {
    this.posts = [];
    this.postsLoaded = false;

    this.feed.fetch(this.searchQuery).then(posts => {
        this.posts = posts;
        this.postsLoaded = true;
    });
}

@brandyscarney
Copy link
Member

brandyscarney commented Apr 29, 2016

So this is because the input is cleared when clicking on the cancel button (and the input event gets emitted on the clear function). We could add a check that the input has a value prior to clearing it and only emit the input event when there is.

https://github.com/driftyco/ionic/blob/2.0/ionic/components/searchbar/searchbar.ts#L313

@brandyscarney
Copy link
Member

Thanks for the issue. This will be fixed in the beta 9 release!

@brandyscarney brandyscarney added this to the 2.0.0-beta.9 milestone Jun 9, 2016
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants