sudhi
March 12, 2009, 3:18pm
1
Hi,
I have a text area with id:“text_area” and in a link_to_remote tag I
want to add content into the text area
I tried (Syntax was correct though not the exact one as below)
link_to_remote (update: “text_area”,
url : { action => “update_text”},
position: bottom
)
The update_text action in the controller had
render :text => “This is new line”
THis does not work for text area, any help in the aspect would be good.
If I have a div instead of text area it works but not for the text_area
only.
Thanks,
Sudhindra
sudhi
March 13, 2009, 1:04pm
2
You dont need an Ajax call for this. RJS is enough.
in helper
def add_text_link(name)
link_to_function name do |page|
page[:text_area] = “This is new line”
end
end
in view
<%= add_text_link “Insert text into text area using JS” %>
On Mar 12, 7:18 pm, Sudhi K. [email protected]
sudhi
March 17, 2009, 7:02am
3
Ram wrote:
You dont need an Ajax call for this. RJS is enough.
in helper
def add_text_link(name)
link_to_function name do |page|
page[:text_area] = “This is new line”
end
end
in view
<%= add_text_link “Insert text into text area using JS” %>
On Mar 12, 7:18?pm, Sudhi K. [email protected]
Hi Ram,
Thanks for the help… this works but I have another question now what
if I need to append into the text area instead of replacing the content?
Thanks,
Sudhi
sudhi
March 17, 2009, 8:22am
4
On 17 Mar., 07:02, Sudhi K. [email protected]
wrote:
Hi Ram,
Thanks for the help… this works but I have another question now what
if I need to append into the text area instead of replacing the content?
def add_text_link(name)
link_to_function name do |page|
page[:text_area] << “This is new line”
end
end
–
Cheers,
David K.
http://twitter.com/rubyguy
sudhi
March 17, 2009, 11:18am
5
[email protected] wrote:
On 17 Mar., 07:02, Sudhi K. [email protected]
wrote:
Hi Ram,
Thanks for the help… this works but I have another question now what
if I need to append into the text area instead of replacing the content?
def add_text_link(name)
link_to_function name do |page|
page[:text_area] << “This is new line”
end
end
–
Cheers,
David K.
http://twitter.com/rubyguy
Hi David,
I tried this but it does not work. For the text area update to work with
IE for a single line I had to do
link_to_function name do |page|
page[:text_area].value = "Hello world"
end
Please note the .value that I use, without using .value it does not work
… so for appending I tried
page[:text_area].value << “This is new line”
This also did not work. Need further help…
Thanks,
Sudhindra
sudhi
March 17, 2009, 3:46pm
6
On 17 Mar., 11:18, Sudhi K. [email protected]
wrote:
end
Please note the .value that I use, without using .value it does not work
… so for appending I tried
page[:text_area].value << “This is new line”
This also did not work. Need further help…
page[:text_area].insert_html :bottom, “The new line”
This should work properly. The documentation for the methods available
in RJS is located here, if you want to take a closer look:
http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html
–
Cheers,
David K.
http://twitter.com/rubyguy
sudhi
March 17, 2009, 10:48pm
7
render :text => “This is new line”
You could say:
render :inline => “<%= text_field ‘test’, ‘name’ %>”
This would just re-populate the div you are trying to update with the
above helper code.
-S
sudhi
March 18, 2009, 6:17am
8
its inner HTML. So use
On Mar 18, 8:53 am, Sudhi K. [email protected]
sudhi
March 18, 2009, 4:53am
9
Shandy N. wrote:
render :text => “This is new line”
You could say:
render :inline => “<%= text_field ‘test’, ‘name’ %>”
This would just re-populate the div you are trying to update with the
above helper code.
-S
Hi,
Thanks for all the inputs. The following line works fine
page.insert_html :bottom,'text_area', "Hello world"
That raises one more question
I want the text in the text_area to look like
Hello world1
Hello world2
hello world3
So to get this if I add
page.insert_html :bottom,‘text_area’, “Hello world\r\n”
The line breaks don’t display in the text area … how do I get that
working?
Thanks,
Sudhindra
sudhi
March 19, 2009, 5:55am
10
My suggestion was just a try.Just try everything you can think of with
your code. its not going to affect anything else as far as i can see.
It would help if you tell us more about what the error was.
Take a look at prototype.js api docs. Wouldnt take more than a couple
of hours to go through the whole thing and it really helps.
www.prototypejs.org/api
Also look out for RJS tutorials. Railscasts episodes 43-45 are good
ones. #43 AJAX with RJS - RailsCasts
Here’re a few RJS cheatsheets for quick reference
http://thebitt.com/dropbox/rails/rjs_cheatsheet.pdf ,
http://slash7.com/assets/2006/10/8/RJS-Demistified_Amy-Hoy-slash7_1.pdf
Search the net thoroughly. More often than not, you can find a
solution or the question has already been asked on some forum.
And when you get errors that you cant resolve, post as much about them
as you can so that others can help you.
On Mar 18, 11:38 am, Sudhi K. [email protected]
sudhi
March 18, 2009, 7:38am
11
Ram wrote:
its inner HTML. So use
On Mar 18, 8:53�am, Sudhi K. [email protected]
Hi Ram,
I tried but once I add br it says it is an RJS Error. Don’t know
why … the snippet I used is
link_to_function name do |page|
page.insert_html :bottom,'text_area', "Hello world <br/>"
end
Thanks,
Sudhindra
sudhi
March 20, 2009, 5:29am
12
$(‘text_area’).value += (“\n Hello world” + name)
that should work or try…
$(‘text_area’).value += (“\n Hello world” + "#{name} ")
But seriously… keep trying different ways to get the result. you’ll
hit it just by brute force.
On Mar 19, 3:48 pm, Sudhi K. [email protected]
sudhi
March 19, 2009, 11:48am
13
Ram wrote:
My suggestion was just a try.Just try everything you can think of with
your code. its not going to affect anything else as far as i can see.
It would help if you tell us more about what the error was.
Take a look at prototype.js api docs. Wouldnt take more than a couple
of hours to go through the whole thing and it really helps.
Prototype API Documentation | Home (Deprecated URL)
Also look out for RJS tutorials. Railscasts episodes 43-45 are good
ones. #43 AJAX with RJS - RailsCasts
Here’re a few RJS cheatsheets for quick reference
http://thebitt.com/dropbox/rails/rjs_cheatsheet.pdf ,
http://slash7.com/assets/2006/10/8/RJS-Demistified_Amy-Hoy-slash7_1.pdf
Search the net thoroughly. More often than not, you can find a
solution or the question has already been asked on some forum.
And when you get errors that you cant resolve, post as much about them
as you can so that others can help you.
On Mar 18, 11:38�am, Sudhi K. [email protected]
Hi Ram,
The articles you sent and the previous posts helped me find this to get
the stuff working but that leaves me with a new problem
With the below RJS
def add_text_link(name)
link_to_function name do |page|
begin
page << <<-‘end’
$(‘text_area’).value += “\n Hello world” ;
end
end
I added above code in the RJS, this works but if I need to use the name
parameter that is passed in how do I do it?
I tried #{name} but no luck…
Thanks,
Sudhindra