You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why can't the enter key just give a line break? (for textarea)
I worked around the issue with the enter key callback function, but I think it would be nice if this functionality could exist by default.
// The callback function of the Enter key. This function will be called when the enter key has been clicked.
keysEnterCallback: function(input) {
if (input.tagName.toLowerCase() === "textarea") {
// event for input element trigger change: begin
var changeEvent = new Event('change', {
'bubbles': true,
'cancelable': true,
});
// event for input element trigger change: end
// input trigger focus
input.focus();
// key's value
var keyValue = '\n';
var keyValArr = keyValue.split('');
theInputValArray = input.value.split('');
for (var keyValIndex = 0; keyValIndex < keyValArr.length; keyValIndex++) {
// update the selectionStart
theInputSelIndex = input.selectionStart || (input.value || '').length;
// add value by index
theInputValArray.splice(theInputSelIndex, 0, keyValArr[keyValIndex]);
// update input value
input.value = theInputValArray.join('');
// set next selection index
if (input.type !== 'number') {
input.setSelectionRange(theInputSelIndex + 1, theInputSelIndex + 1);
}
// input trigger change event for update the value
input.dispatchEvent(changeEvent);
}
}
},
So I had to modify the source code a little bit to :
Why can't the enter key just give a line break? (for textarea)
I worked around the issue with the enter key callback function, but I think it would be nice if this functionality could exist by default.
So I had to modify the source code a little bit to :
Thank you very much for this lovely piece of work. It takes a big thorn out of my side.
The text was updated successfully, but these errors were encountered: