Forum: Ruby on Rails Keypress events with no AJAX needed

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris H. (Guest)
on 2006-03-13 16:54
Is anyone else finding it frustrating to do in Ruby client-side things
that would be simple in Javascript?
It seems like all of the "helpers" involve server (controller)
communication.

For example, having a text field that just echos below what the user
types.
Is this the only way to do it?

<div id='word_panel'>
			<%= text_field_tag 'user_text'%>
			<%=	javascript_tag("Event.observe('user_text', 'keypress',
							function(event) { Element.update('stylized_word',
									$F(Event.element(event)));})")%>

<div id='show_word'></div>


Thank you!
Chris
Cheltis (Guest)
on 2006-03-13 17:23
Chris, this is just the example. You might want to use that for chat for
example, where text that user types appears not only on his computer,
but for others.

Clearly, if you are doing it for one user there is no point in using
server-side, but again this is just the example
Chris H. wrote:
> Is anyone else finding it frustrating to do in Ruby client-side things
> that would be simple in Javascript?
> It seems like all of the "helpers" involve server (controller)
> communication.
>
> For example, having a text field that just echos below what the user
> types.
> Is this the only way to do it?
>
> <div id='word_panel'>
> 			<%= text_field_tag 'user_text'%>
> 			<%=	javascript_tag("Event.observe('user_text', 'keypress',
> 							function(event) { Element.update('stylized_word',
> 									$F(Event.element(event)));})")%>
>
> <div id='show_word'></div>
>
>
> Thank you!
> Chris
Alex Y. (Guest)
on 2006-03-13 17:31
(Received via mailing list)
Chris H. wrote:
> Is anyone else finding it frustrating to do in Ruby client-side things
> that would be simple in Javascript?
> It seems like all of the "helpers" involve server (controller)
> communication.
The reason for that is extremely simple.  Where there's server
communication, you need a convenient way of keeping the client-side and
server-side code in sync.  That's what the helpers help with.  If all
you're doing is client-side manipulation, you almost certainly don't
need the helpers.  Just use Javascript.

>
> For example, having a text field that just echos below what the user
> types.
> Is this the only way to do it?
Personally, I wouldn't bother with the <%= javascript_tag %> call at
all...
This topic is locked and can not be replied to.