Question: how can I grab the newlines in a string entered into a textbox created as described below?
Motivation: I am trying to make a couple really simple modifications to a FireFox extension (Zotero) to make it easier for me to use. This extension allows you to enter tags for an item by typing them into a textbox and hitting enter. I would like to be able to enter a bunch of tags at once by pasting them into the textbox as a string with newline as the delimiter between tags. newline was chosen because other characters are viable choices for use in the tag itself.
Problem: when I paste a string into the entry textbox right now, it strips out all of the newlines and replaces them with single spaces. I can’t find anywhere in the extension code where this happens, so I think it is a property of the textbox itself. I am trying to look up documentation for this textbox to see if there are some properties I can play with so that I can catch the newlines, but I am not very familiar with JavaScript and HTML and am having trouble finding anything. I’d like to find the least invasive solution possible (one that doesn’t change the way the textbox currently works for typing in new entries and hitting enter) so that this modification could be adopted into the core version of the extension.
Resources: so far the only thing I have found online discussing a similar issue is this other question about allowing tab in a textbox but not newline. I am not sure if this is an HTML issue (is there a property that could be set to allow the newlines to be retained?) or a JavaScript one (do I need to rewrite the code quoted below?). I have been trying to look at documentation for both but have not found anything so far (most HTML tutorials discuss textarea rather than textbox).
Code: here is the code that creates the textbox object (or is it a method or a form?) I am dealing with:
<method name="showEditor">
<parameter name="elem"/>
<body>
<![CDATA[
// Blur any active fields
/*
if (this._dynamicFields) {
this._dynamicFields.focus();
}
*/
Zotero.debug('Showing editor');
var fieldName = 'tag';
var tabindex = elem.getAttribute('ztabindex');
var tagID = elem.parentNode.getAttribute('id').split('-')[1];
var value = tagID ? Zotero.Tags.getName(tagID) : '';
var itemID = Zotero.getAncestorByTagName(elem, 'tagsbox').item.id;
var t = document.createElement("textbox");
t.setAttribute('value', value);
t.setAttribute('fieldname', fieldName);
t.setAttribute('ztabindex', tabindex);
t.setAttribute('flex', '1');
// Add auto-complete
t.setAttribute('type', 'autocomplete');
t.setAttribute('autocompletesearch', 'zotero');
var suffix = itemID ? itemID : '';
t.setAttribute('autocompletesearchparam', fieldName + '/' + suffix);
var box = elem.parentNode;
box.replaceChild(t, elem);
// Prevent error when clicking between a changed field
// and another -- there's probably a better way
if (!t.select) {
return;
}
t.select();
t.addEventListener('blur', function () {
document.getBindingParent(this).blurHandler(this);
}, false);
t.setAttribute('onkeypress', "return document.getBindingParent(this).handleKeyPress(event)");
this._tabDirection = false;
this._lastTabIndex = tabindex;
return t;
]]>
</body>
</method>
This question is actually about XUL, not HTML. The documentation for the textbox object can be found here:
https://developer.mozilla.org/en/XUL/textbox
The property that needs to be set is newlines. By setting this to ‘pasteintact’ the newlines can be retained.