If you take the example from the second link, you'll need to use the
whole submitViaEnter(evt) function anyway.
Only for form building rails code can be used and then in the text_field
:onkeypress="return submitViaEnter(event)"
I'm not sure though, if that would work with a text area. (At least
you'll lose the multiline functionality)
--
Posted via http://www.ruby-forum.com/.
brian scott wrote:
> i've searched for a way to submit a form with the
> enter key, but haven't found the rails way to do it.
My experience has been that if you've got a form in the browser and you hit
the enter key it submits the thing whether that's what you intended or not.
I'm on Windows so that may play a role in it. Does your Rails app behave
differently?
HTH,
Bill
You'll need to install a handler on the textarea for the keypress event,
then call submit() directly on the form if the ENTER key is pressed.
If you add :wrap => 'soft' to your text_area call, it should prevent
the scrollbar appearing.
See : http://www.idocs.com/tags/forms/_TEXTAREA_WRAP.html for more options.
If you're using prototype.js:
Event.observe('id-of-the-textarea', 'keypress', function(event) {
if (event.keyCode == Event.KEY_RETURN && !event.altKey &&
!event.shiftKey) {
this.up('form').submit();
Event.stop(event);
}
};
- D