Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preventSubmitOnEnter only for textarea #415

Open
cniklas opened this issue Oct 11, 2020 · 1 comment
Open

preventSubmitOnEnter only for textarea #415

cniklas opened this issue Oct 11, 2020 · 1 comment
Assignees
Labels

Comments

@cniklas
Copy link

cniklas commented Oct 11, 2020

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?

@cniklas
Copy link
Author

cniklas commented Oct 19, 2020

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants