I tried searching, but am not finding a solution.
I am currently using Jquery autocomplete, along with an external service that stores the lists of possible returned results. The autocomplete is being done on a textarea, and I need to try to autocomplete for each line of text. So the user types one line, gets auto complete. Goes to a new line, starts typing, autocomplete appears only for what's on that line.
The set up is pretty standard to what JQuery shows off. I.E.:
<textarea id="entities"></textarea>
JS:
$("#entities").autocomplete({
serviceUrl: [the service url],
paramName: 'prefix'
});
I know there are ways to determine line number and get the value of a specific line such as:
$("#entities").on('keyup', function() {
var textLines = $("#entities").val().substr(0, $("#entities").selectionStart).split("\n");
var currentLineNumber = textLines.length - 1;
console.log(lines[currentLineNumber]);
});
But I'm not sure how I could call the autocomplete function upon typing a new line.
Edit: Someone suggested using contentEditable, but this results in different wrappers for each line depending on the browser.
<div id="entities" class="entities-text" contenteditable="true"></div>
IE converts each line to:
<p>Line 1</p>
<p>Line 2</p>
FF shows:
Line 1<br>
Line 2<br>
Chrome gives:
<div>Line 1</div>
<div>Line 2</div>