Forum: Ruby on Rails Lin_to_remote and update a text area

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.
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-03-12 15:18
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
2dddec0f7717cae77ac6bceede6be5bc?d=identicon&s=25 Ram (Guest)
on 2009-03-13 13:04
(Received via mailing list)
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 Kulkarni <rails-mailing-l...@andreas-s.net>
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-03-17 07:02
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 Kulkarni <rails-mailing-l...@andreas-s.net>

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
36ed63ef68c172f148c491418395d0b5?d=identicon&s=25 rubyguy@ymail.com (Guest)
on 2009-03-17 08:22
(Received via mailing list)
On 17 Mar., 07:02, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net>
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 Knorr
http://twitter.com/rubyguy
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-03-17 11:18
rubyguy@ymail.com wrote:
> On 17 Mar., 07:02, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net>
> 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 Knorr
> 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
36ed63ef68c172f148c491418395d0b5?d=identicon&s=25 rubyguy@ymail.com (Guest)
on 2009-03-17 15:46
(Received via mailing list)
On 17 Mar., 11:18, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net>
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/Help...

--
Cheers,
David Knorr
http://twitter.com/rubyguy
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2009-03-17 22:48
> 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
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-03-18 04:53
Shandy Nantz 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
2dddec0f7717cae77ac6bceede6be5bc?d=identicon&s=25 Ram (Guest)
on 2009-03-18 06:17
(Received via mailing list)
its inner HTML. So use <br/>

On Mar 18, 8:53 am, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net>
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-03-18 07:38
Ram wrote:
> its inner HTML. So use <br/>
>
> On Mar 18, 8:53�am, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net>

Hi Ram,

I tried <br/> 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
2dddec0f7717cae77ac6bceede6be5bc?d=identicon&s=25 Ram (Guest)
on 2009-03-19 05:55
(Received via mailing list)
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. www.railscasts.com/episodes/43

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...

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 Kulkarni <rails-mailing-l...@andreas-s.net>
C95664a5c59ccdfb0da2f5910675c62c?d=identicon&s=25 Sudhi Kulkarni (sudhi)
on 2009-03-19 11:48
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.
> www.prototypejs.org/api
>
> Also look out for RJS tutorials. Railscasts episodes 43-45 are good
> ones. www.railscasts.com/episodes/43
>
> 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...
>
> 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 Kulkarni <rails-mailing-l...@andreas-s.net>

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
2dddec0f7717cae77ac6bceede6be5bc?d=identicon&s=25 Ram (Guest)
on 2009-03-20 05:29
(Received via mailing list)
$('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 Kulkarni <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.