If you define a handler for 'chosen:no_results' event its pretty tricky to get the text (what provided the 'no result') from user input.
Could you please add a function (or extra parameter to the callback) to make it possible to get the text from the input field?
+1
Seconded. It seems that the current method doesn't actually pass the terms through, though I was able to grab them in a super awkward way:
$('.select--chosen').on('chosen:no_results', function(event, parameters) {
console.log(parameters.chosen.search_results[0].textContent.match(/No results match "(.+)"/)[1])
});
Has anyone any idea how to solve that problem?
@dzeju555 which problem? The code I posted above makes it possible to grab the text the user typed, it's just a bit awkward. Otherwise, a pull request needs to make changes to the library to give us an easier way to get at the data.
I mean, the easier way to do that. I have to do a selectlist which allows user to select an option. But if there is no option user typed, I have to add it to a database dictionary. I though that it will be a good option that Chosen could sent typed text in form with another input fields to my controller (I use MVC application) and there I would do the rest. What is important, I want typed text to be still in Chosen field, now it disappears when Chosen is closed and user is not sure what will be sent to the database. I will try to replace placeholder with typed text in jQuery when not found trigger is ran.
var obs = $('select').chosen({width: '100%'}).data('chosen');
obs.search_field.on('keyup', function(e){
console.log($(this).val());
});
+1
Maybe this can works.
$('.select-chosen').on('chosen:no_results', function(event, element){
console.log($(element.chosen.search_results).find('span').text());
});
This is already possible:
$('.chosen-select').on('chosen:no_results', function(event, data){
console.log(data.chosen.get_search_text());
});
Most helpful comment