I am using MagicSuggest and I need to get the length of the selections on a blur event. My code works great if I add a new selection via the ENTER key but does not work if I choose an existing selection from the list.
Use cases
- if User chooses suggestions via the ENTER key, length = 1 - Correct
- if User chooses suggestions via the MOUSE click, length = 0 - Incorrect, should be 1
JSfiddle https://jsfiddle.net/a1ejqtae/7/
HTML
<form action="">
<label for="keyword">Keywords</label>
<input type="text" id="keywords">
</form>
JS
$('form input').on('blur', function(){
var selectionLength = $('form .ms-sel-item').length;
$('.selection-name').text(selectionLength);
console.log('Selection is ' + selectionLength);
if( selectionLength > 0 ){
console.log('Selection is greater than 0');
}
});
PS Does anyone know what happened to this plugin, the github page is still running but the site with all documentation and examples is down - http://nicolasbize.com/magicsuggest/doc.html. Thank goodness for wayback machine.