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

onSubmit triggered twice if there is result for the search #182

Closed
w-sharp opened this Issue Apr 15, 2016 · 9 comments

Comments

Projects
None yet
2 participants
@w-sharp

w-sharp commented Apr 15, 2016

Hi;
I am using version 2.4.0. When i use an alert in obSubmit it is triggered twice if there is a result in the list so alert shown twice. If there is no result in the list it is ok and it is showing alert once.

Am i doing something wrong?

Here is my code


var originalQuery = '';

    $('#sb').typeahead({
        minLength: 2,
        maxItem: 5,
        hint: false,
        highlight: true,
        mustSelectItem: false,
        emptyTemplate: "No Result",
        display: ["title", "writer", "supporter", "owner", "target"],
        template: "{{title}}, <small><em>{{author}}</em></small>",
        backdrop: {
            "background-color": "#333"
        },
        source: {
            url: ["ProductList.json"],
        dataType: "json"
        },
        callback: {
            onClickBefore: function (node, a, item, event) {
                // Save the query to be re-used in onClickAfter
                originalQuery = this.query;
            },
            onClickAfter: function (node, query, item, event) {
                event.preventDefault();
                window.location = (item.target+'?q='+originalQuery);
            },
            onSubmit: function (node, form, item, event) {
                alert('You should select an item in result');
                return false;
            },
        },

        debug: false
    });

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 15, 2016

Hey sharp, I'll double-check this afternoon your init seems fine might be a problem on Typeahead's side. Thanks for letting me know perhaps check if 2.5.1 is giving you the issue as well?

@w-sharp

This comment has been minimized.

w-sharp commented Apr 15, 2016

I have upgraded to 2.5.1 to test. I didnt find any note or doc for upgrading but i have found in the demo that html part is changed so i also changed in my implementation. But i have seeing and error and i couldn't get it work.

http://share.pho.to/A6xYX/ut/original
http://share.pho.to/A6xYX/tx/original

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 15, 2016

I was able to reproduce the error (i think), it is caused by searching for an undefined key or numeric value instead of string (see screenshot) I'll add some fail-safe code around that case
2016-04-15_1650

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 15, 2016

Regarding the upgrade notes, you can look at version page the template was updated as well as group and dropdownFilter options

@running-coder running-coder added the Bug label Apr 15, 2016

@running-coder running-coder added this to the 2.6.0 milestone Apr 15, 2016

@w-sharp

This comment has been minimized.

w-sharp commented Apr 15, 2016

Yes, you right. When i found and remove -for the moment- the key that sometime not present in the json it is working.

Then i was able to make the test to see if submit problem (triggered twice) occurs in the version 2.5.1. Unfortunately it is the same with latest version too.

Thanks

PS: about the template change. Silly me, i have read that section yet didn't understand it, when i read it second time then finally i make the connection :) Sorry about that.

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 15, 2016

found out the issue, it comes from here will include a fix in the next commit

running-coder added a commit that referenced this issue Apr 15, 2016

#182 - Fixed double form submit when the "Enter" key is pressed
#182 - Fixed JS error when searching for an undefined or numeric value

- Added unit tests around `cleanStringFromScript` helper function

running-coder added a commit that referenced this issue Apr 15, 2016

#182 - Fixed double form submit when the "Enter" key is pressed
#182 - Fixed JS error when searching for an undefined or numeric value

- Added unit tests around `cleanStringFromScript` helper function
@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 15, 2016

Should be good now, lmk

@w-sharp

This comment has been minimized.

w-sharp commented Apr 15, 2016

Yeap, it seems both issues (submitting twice and undefined key) are done. Script works fine. Thanks again.

@w-sharp w-sharp closed this Apr 15, 2016

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 15, 2016

amazing, thanks

running-coder added a commit that referenced this issue Apr 22, 2016

Version 2.6.0
*Breaking change*
- Update Typeahead source option: source.group.url.url has been replaced by source.group.ajax.url

Features
- #69, #179 Added groupTemplate option
- #183 Allow Typeahead to search for deep source object keys

Fixes
- #149 Support for Mobiles
- #181 IE8 incompatibility
- #182 Fixed double form submit when the "Enter" key is pressed & fixed JS error when searching for an undefined or numeric value
- #184 Invalid encoded characters on dynamic requests for `{{query}}`

Notes
- Reworked the source.group options, url has been replaced by ajax
- Removed the source.group.ignore option, use source.group.filter instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment