Skip to content

fire onSelect, if only one result is returned #846

Closed
@svennd

Description

@svennd

If there is only a single suggestion, I would like to fire "onSelect". The reason : beside normal text, I also can receive (long) barcodes on the field. If this is the case, I don't need the extra interaction from the user.
autoSelectFirst : will select the first field but an enter is still required; (which is confusing since it might fire the entire form)

I tried with onSearchComplete, since this is a ajax call. But I can't (or don't know how) to fire onSelect function.

$('#autocomplete').autocomplete({

	serviceUrl: 'get_product',
	
	onSelect: function (suggestion) {
		console.log("onselect shot");
		var res = suggestion.data;
		$("#pid").val(res.id);
		// some more code
	},
	onSearchComplete: function (query, suggestion) { 

		if(suggestion.length == 1 && query.length > 20)
		{
			this.OnSelect(0); // this is invalid
		}
	},
	autoSelectFirst: true,
	minChars: '2'
});

I also tried with onHint, but then I have no idea when there is only 1 result. If I missed the obvious, sorry ! Thanks for this wonderful library !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions