Andrew Cowan
2006-Apr-14 16:07 UTC
[Rails] Whats the best Ajax way to update a textarea''s text?
I am looking for a way to update the text-value within a textarea from an Ajax render call inside of a controller. Is there a way to do this without rendering an the partial containing the textarea? Thanks, Andy -- Posted via http://www.ruby-forum.com/.
Roberto Saccon
2006-Apr-14 16:43 UTC
[Rails] Whats the best Ajax way to update a textarea''s text?
just set the value of the textarea element with a RJS On 4/14/06, Andrew Cowan <icculus@gmdstudios.com> wrote:> > > I am looking for a way to update the text-value within a textarea from > an Ajax render call inside of a controller. Is there a way to do this > without rendering an the partial containing the textarea? > > Thanks, > Andy > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Roberto Saccon - http://rsaccon.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060414/fb55a5ab/attachment.html
Andrew Cowan
2006-Apr-14 16:47 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
Disregard, I believe I found a working solution with the following:
render :update do |page|
page[''messages''].value = @messages
end
where ''messages'' is the id of the textarea and @messages is
updated in
the controller with the current state of the text.
Looks to be working, if anyone sees a reason why this may be a problem
and has a better solution I''d love to hear it. :)
-Andy
Andrew Cowan wrote:>
> I am looking for a way to update the text-value within a textarea from
> an Ajax render call inside of a controller. Is there a way to do this
> without rendering an the partial containing the textarea?
>
> Thanks,
> Andy
--
Posted via http://www.ruby-forum.com/.
Michael Trier
2006-Apr-14 16:55 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
I was looking for this same solution just the other day, so thank you. Michael
Michael Trier
2006-Apr-14 18:05 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
This doesn''t appear to work with a text_field_tag unless I''m missing something. Have: page.email.value = '''' to clear the text field. email is the ID of my input control. Any ideas? Michael
Andrew Cowan
2006-Apr-14 18:44 UTC
[Rails] Re: Re: Whats the best Ajax way to update a textarea''s text?
This does work for me with text_fields also, although I reference the element by page[''element_id''].value instead of page.element_id.value -Andy Michael Trier wrote:> This doesn''t appear to work with a text_field_tag unless I''m missing > something. Have: > > page.email.value = '''' > > to clear the text field. email is the ID of my input control. Any > ideas? > > Michael-- Posted via http://www.ruby-forum.com/.
Michael Trier
2006-Apr-14 19:06 UTC
[Rails] Re: Re: Whats the best Ajax way to update a textarea''s text?
Interesting. Thought I tried it both ways, just tried again and it works. Thanks. Michael
Bill Walton
2006-Apr-20 14:51 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
Hi Andy,
I''m trying to clear the input fields on a form and was really glad to
find
this thread. Unfortunately, I''ve tried this just about every way I can
think of and instead of clearing the fields, it''s clearing pretty much
the
whole page. I would ***really*** appreciate some help!
The page has a form that allows the entry of two fields. The form exists
inside a <div> with id=Entryline. When the user clicks the button, a new
line is added to the page inside a <div> with id=ingredient_list. The
user
can add as many lines as they want. I want to clear the fields each time
they click the button. What''s happening instead is that the Entryline
<div>
and everything above it on the page is getting wiped out. The code is
below. Any ideas?
Thanks in advance,
Bill
--- Here''s _entry_form.rhtml ---
<%= form_remote_tag(:update => ''ingredient_list'',
:url => {:action => :add_ingredient},
:position => ''bottom'',
:after => {:action => :clear_entry}) %>
Name:
<%= text_field_tag :name %>
Amount:
<%= text_field_tag :qty %>
<%= submit_tag ''Add Ingredient'' %>
<%= end_form_tag %>
--- and here''s the clear_entry action in the controller ----
def clear_entry
render :update do |page|
page.Entryline.name.value = ''''
page.Entryline.qty.value = ''''
end
end
----- Original Message -----
From: "Andrew Cowan" <icculus@gmdstudios.com>
To: <rails@lists.rubyonrails.org>
Sent: Friday, April 14, 2006 11:47 AM
Subject: [Rails] Re: Whats the best Ajax way to update a textarea''s
text?
> Disregard, I believe I found a working solution with the following:
>
> render :update do |page|
> page[''messages''].value = @messages
> end
>
> where ''messages'' is the id of the textarea and @messages
is updated in
> the controller with the current state of the text.
>
> Looks to be working, if anyone sees a reason why this may be a problem
> and has a better solution I''d love to hear it. :)
>
> -Andy
>
>
> Andrew Cowan wrote:
>>
>> I am looking for a way to update the text-value within a textarea from
>> an Ajax render call inside of a controller. Is there a way to do this
>> without rendering an the partial containing the textarea?
>>
>> Thanks,
>> Andy
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Cody Fauser
2006-Apr-20 21:05 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
Bill,
The :after callback doesn''t make a remote Ajax call and
doesn''t really
need to. Try this to reset the fields:
<%= form_remote_tag(:update => ''ingredient_list'',
:url => {:action => :add_ingredient},
:position => ''bottom'',
:after =>
''Form.reset(this)''
) %>
This will just call the Prototype form helper to reset your form. If
you are using RJS in your add_ingredient action then you could just do
the resetting from your RJS template.
Just give the form an id with :html => { :id =>
''entry-form'' } and
then in RJS you could use a JavaScript class proxy like follows:
page.form.reset ''entry-form''
Also, if your controller action ''add_ingredient'' renders an
RJS
template or uses inline RJS then you don''t want to use the :update
option in your link_to_remote method call. This could be causing your
strange problems.
On 4/20/06, Bill Walton <bill.walton@charter.net>
wrote:> Hi Andy,
>
> I''m trying to clear the input fields on a form and was really glad
to find
> this thread. Unfortunately, I''ve tried this just about every way
I can
> think of and instead of clearing the fields, it''s clearing pretty
much the
> whole page. I would ***really*** appreciate some help!
>
> The page has a form that allows the entry of two fields. The form exists
> inside a <div> with id=Entryline. When the user clicks the button, a
new
> line is added to the page inside a <div> with id=ingredient_list.
The user
> can add as many lines as they want. I want to clear the fields each time
> they click the button. What''s happening instead is that the
Entryline <div>
> and everything above it on the page is getting wiped out. The code is
> below. Any ideas?
>
> Thanks in advance,
> Bill
>
> --- Here''s _entry_form.rhtml ---
> <%= form_remote_tag(:update => ''ingredient_list'',
> :url => {:action => :add_ingredient},
> :position => ''bottom'',
> :after => {:action => :clear_entry}) %>
> Name:
> <%= text_field_tag :name %>
> Amount:
> <%= text_field_tag :qty %>
> <%= submit_tag ''Add Ingredient'' %>
> <%= end_form_tag %>
>
> --- and here''s the clear_entry action in the controller ----
> def clear_entry
> render :update do |page|
> page.Entryline.name.value = ''''
> page.Entryline.qty.value = ''''
> end
> end
> ----- Original Message -----
> From: "Andrew Cowan" <icculus@gmdstudios.com>
> To: <rails@lists.rubyonrails.org>
> Sent: Friday, April 14, 2006 11:47 AM
> Subject: [Rails] Re: Whats the best Ajax way to update a
textarea''s text?
>
>
> > Disregard, I believe I found a working solution with the following:
> >
> > render :update do |page|
> > page[''messages''].value = @messages
> > end
> >
> > where ''messages'' is the id of the textarea and
@messages is updated in
> > the controller with the current state of the text.
> >
> > Looks to be working, if anyone sees a reason why this may be a problem
> > and has a better solution I''d love to hear it. :)
> >
> > -Andy
> >
> >
> > Andrew Cowan wrote:
> >>
> >> I am looking for a way to update the text-value within a textarea
from
> >> an Ajax render call inside of a controller. Is there a way to do
this
> >> without rendering an the partial containing the textarea?
> >>
> >> Thanks,
> >> Andy
> >
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Cody Fauser
http://www.codyfauser.com
Cody Fauser
2006-Apr-20 21:13 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
Michael,
You were trying to use a class proxy instead of an element proxy.
Compare the JavaScript generated by the following:
# Class proxy
page.email.value = '''' # => Email.value = "";
# Element proxy
page[''email''].value = '''' # =>
$("email").value = "";
On 4/14/06, Michael Trier <mtrier@gmail.com>
wrote:> This doesn''t appear to work with a text_field_tag unless
I''m missing
> something. Have:
>
> page.email.value = ''''
>
> to clear the text field. email is the ID of my input control. Any ideas?
>
> Michael
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Cody Fauser
http://www.codyfauser.com
Bill Walton
2006-Apr-20 21:22 UTC
[Rails] Re: Whats the best Ajax way to update a textarea''s text?
Cody,
Thank you! Perfect.
Best regards,
Bill
----- Original Message -----
From: "Cody Fauser" <codyfauser@gmail.com>
To: <rails@lists.rubyonrails.org>
Sent: Thursday, April 20, 2006 4:05 PM
Subject: Re: [Rails] Re: Whats the best Ajax way to update a textarea''s
text?
Bill,
The :after callback doesn''t make a remote Ajax call and
doesn''t really
need to. Try this to reset the fields:
<%= form_remote_tag(:update => ''ingredient_list'',
:url => {:action => :add_ingredient},
:position => ''bottom'',
:after =>
''Form.reset(this)''
) %>
This will just call the Prototype form helper to reset your form. If
you are using RJS in your add_ingredient action then you could just do
the resetting from your RJS template.
Just give the form an id with :html => { :id =>
''entry-form'' } and
then in RJS you could use a JavaScript class proxy like follows:
page.form.reset ''entry-form''
Also, if your controller action ''add_ingredient'' renders an
RJS
template or uses inline RJS then you don''t want to use the :update
option in your link_to_remote method call. This could be causing your
strange problems.
On 4/20/06, Bill Walton <bill.walton@charter.net>
wrote:> Hi Andy,
>
> I''m trying to clear the input fields on a form and was really glad
to find
> this thread. Unfortunately, I''ve tried this just about every way
I can
> think of and instead of clearing the fields, it''s clearing pretty
much the
> whole page. I would ***really*** appreciate some help!
>
> The page has a form that allows the entry of two fields. The form exists
> inside a <div> with id=Entryline. When the user clicks the button, a
new
> line is added to the page inside a <div> with id=ingredient_list.
The
> user
> can add as many lines as they want. I want to clear the fields each time
> they click the button. What''s happening instead is that the
Entryline
> <div>
> and everything above it on the page is getting wiped out. The code is
> below. Any ideas?
>
> Thanks in advance,
> Bill
>
> --- Here''s _entry_form.rhtml ---
> <%= form_remote_tag(:update => ''ingredient_list'',
> :url => {:action => :add_ingredient},
> :position => ''bottom'',
> :after => {:action => :clear_entry}) %>
> Name:
> <%= text_field_tag :name %>
> Amount:
> <%= text_field_tag :qty %>
> <%= submit_tag ''Add Ingredient'' %>
> <%= end_form_tag %>
>
> --- and here''s the clear_entry action in the controller ----
> def clear_entry
> render :update do |page|
> page.Entryline.name.value = ''''
> page.Entryline.qty.value = ''''
> end
> end
> ----- Original Message -----
> From: "Andrew Cowan" <icculus@gmdstudios.com>
> To: <rails@lists.rubyonrails.org>
> Sent: Friday, April 14, 2006 11:47 AM
> Subject: [Rails] Re: Whats the best Ajax way to update a
textarea''s text?
>
>
> > Disregard, I believe I found a working solution with the following:
> >
> > render :update do |page|
> > page[''messages''].value = @messages
> > end
> >
> > where ''messages'' is the id of the textarea and
@messages is updated in
> > the controller with the current state of the text.
> >
> > Looks to be working, if anyone sees a reason why this may be a problem
> > and has a better solution I''d love to hear it. :)
> >
> > -Andy
> >
> >
> > Andrew Cowan wrote:
> >>
> >> I am looking for a way to update the text-value within a textarea
from
> >> an Ajax render call inside of a controller. Is there a way to do
this
> >> without rendering an the partial containing the textarea?
> >>
> >> Thanks,
> >> Andy
> >
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Cody Fauser
http://www.codyfauser.com
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails