Forced selection
See original GitHub issueHey guys! First of all … congratulations. This is really an impressive piece of code. Works better then the 3 others I tried so fare.
In my opinion, you guys are missing only one very important feature … being able to force or not a selection in the list. That feature should take care of all the required behaviour that such a feature would need.
- If the forced option is activated the user should not be able to leave an incomplete keyword
- The selection should be triggered at all time because in some cases there can be an extra hidden field that needs to be updated that contains an ID or something
If somebody has a way of doing it with a few hacks to my code please le me know … This is what i am doing right now
// Activating typeahead on class cp
$('.cp').typeahead({
// forced: true, -> Not working !
name: 'nom',
prefetch: 'ajax_recherche_ville.php',
limit: 50
});
// On sellection, adding a hidden value to ville_id
$('.cp').bind('typeahead:selected', function(obj, datum) {
$('input:hidden[name=ville_id]').val(datum.id);
});
// We do not allow enter on the cp field to avoid incomplete selection
$('.cp').keypress(function (e) {
if (e.which == 13) {
return false;
// This is not a real solution ... it's not a 100% forcing a selection
// The user can clique elsewhere in the screen to close the box
// Or he can clique on the submit button over an incomplete keyword
}
});
If only this was as simple as forced: true!
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Forced choice
Forced choice may refer to: Ipsative, a question that compares two options (in social science); Forcing (magic) · Disambiguation icon.
Read more >When Online Survey Respondents Only 'Select Some That ...
The new study found compelling evidence that forced-choice questions yield more accurate results than select-all-that-apply lists.
Read more >Forced Choice Question: Meaning, Scale + [Survey ...
A forced choice question requires the respondent to provide a specific answer. This type of question eliminates in-between options, ...
Read more >The Effect of Forced Choice on Choice
The no-choice option helps resolve the preference uncertainty and discomfort associated with forced choice in competition with other conflict resolutions.
Read more >Forced-Choice Question: What It Is + Guide wit Examples
A forced-choice question forces survey participants to select an option from the given choices. Learn more about it and how it works.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m interested in this as well.
I need a searchable menu, with all the features of typeahead + bloodhound, but with a hidden field to hold the selected ID and some mechanism to force a selection (and clear the typeahead field if nothing was selected, as a feedback to the user.)
Am I looking at the wrong project to achieve this input type?
Edit: here’s my solution, which seems to be working so far:
My solution: