conversational-form
conversational-form copied to clipboard
preventSubmitOnEnter only for textarea
I already bent my head around this problem but found no satisfying solution.
I would like my users to be able to submit an input element by hitting enter. But I also want them to be able to create new lines in textareas. Seems that this is not possbile at the same time.
Yes, it is possible to create a new line in a textarea by hitting shift + enter
. But this is not a known feature amongst the average internet users. Plus it's impossbile on a touch device.
Can I set preventSubmitOnEnter
just for textareas?
Here is my solution, in case anyone is interested. I updated conversational-form.js
.
line 4527, from:
// prevent textarea line breaks
if (event.keyCode == cf.Dictionary.keyCodes["enter"] && !event.shiftKey) {
event.preventDefault();
}
to:
// prevent textarea line breaks, but not in textareas with `rows` > 1
if (event.keyCode == cf.Dictionary.keyCodes["enter"] && !(this.inputElement.hasAttribute('rows') && parseInt(this.inputElement.getAttribute('rows')) > 1)) {
event.preventDefault();
}
line 4579, from:
if (this.cfReference.preventSubmitOnEnter === true)
to:
if (this.cfReference.preventSubmitOnEnter === true || this._currentTag.type == 'textarea')