Skip to content

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

@w-sharp

Description

@w-sharp

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
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions