RJS help for setting input value

I’d like an interface similar to the del.icio.us one for tags, but
I’m stuck when trying to add the tag name to an input field.
What I’m trying to do is:

page.select(’#tag_names’).each do |element|
if element.value.to_s.empty?
element.value = @tag.name
else
element.value = element.value.to_s + “, #{@tag.name}”
end
end

but it doesn’t work …
Suggestions ?

TIA,
ngw

I would test whether element.value gives you access to the DOM element
in the way you expect.

Here’s a quote from Cody F.'s RJS Templates for Rails that may
have some bearing on what you’re trying to do:

“When using a direct element proxy rather than a string passed to <<,
the generator assumes that the proxied call is a method call and
automatically adds (). This means that you can’t directly proxy an
element’s property, such as
element.innerHTML.
page.select(’#elements span’).any(‘allVisible’) do |value, index|
page << ‘!value.visible()’
end”

Dave

On Mar 12, 4:45 pm, Nicholas W. [email protected]

Il giorno 13/mar/07, alle ore 01:52, Dave ha scritto:

I would test whether element.value gives you access to the DOM element
in the way you expect.

Here’s a quote from Cody F.'s RJS Templates for Rails that may
have some bearing on what you’re trying to do:

Very close, thanks …
It seems to me that I can’t fetch or use what’s inside the value
attribute of the input field, it doesn’t return a string but a
JavascriptElementProxy that doesn’t have a to_str/to_s method.
I need to check if that value is empty, and if not I need to use it
for the new value …
I will never be able to get out from this alone :stuck_out_tongue:

TIA,
ngw

Was this issue ever resolved? if so I would love to know how!!
Jason.

gblasko wrote:

Very close, thanks …
It seems to me that I can’t fetch or use what’s inside thevalue
attribute of the input field, it doesn’t return a string but a JavascriptElementProxythat doesn’t have a to_str/to_smethod.
I need to check if thatvalueis empty, and if not I need to use it
for the newvalue…
I will never be able to get out from this alone :stuck_out_tongue:

Any luck on getting the value? I am running into the same issue.

Thanks,
Greg

On Oct 4, 6:27 am, Jason Franklin-stokes <rails-mailing-l…@andreas-
s.net> wrote:

Was this issue ever resolved? if so I would love to know how!!
Jason.

At the time the RJS runs you cannot find the value of an element: the
rjs is running on the server, but the info is on the client’s page.
So for example,
if page[:something].empty?

or anything like that is impossible.
You can however generate javascript that will check a certain
condition, for example
page << “if($F(‘foo’) == ‘bar’){”
page[:baz].hide()
page << “}”

I waffled about this at some length here:
http://www.spacevatican.org/2008/5/26/conditional-rjs-explained

Fred

Thanks, for the quick reply -
I actually read your article earlier on thanks.

Hmm, now lets see if I am getting this right.
When I write somthing in the RJS file the page object takes my DLD and
transforms it into javascript which is immediatley sent out to the
browser which then does the rendering it has been asked for.

I hope I got that bit right?

As it is possible to send snippits of javascript to the browser and ask
it to get me a value of a DOM back, then I ask by self why this request
cannot be handled by the javascript engine in rails.

The only logical explination to me is that asking the browser and
telling the browser are 2 completely different things.

So that would mean that the rails javascript engine has been written to
handle all the “tell stuff” - but it can’t handle the “ask stuff” i.e.
that engine is probably missing.

Could it be that the underlying problem is that the messaging
(responder, initiator sequence) is entirely differnt depending on what
is being done (asking or telling).

If all this is understandable and the answer is (yes this is how it
works) then I will be relieved to know.

Thanks a million
Jason

Frederick C. wrote:

On Oct 4, 6:27�am, Jason Franklin-stokes <rails-mailing-l…@andreas-
s.net> wrote:

Was this issue ever resolved? if so I would love to know how!!
Jason.

At the time the RJS runs you cannot find the value of an element: the
rjs is running on the server, but the info is on the client’s page.
So for example,
if page[:something].empty?

or anything like that is impossible.
You can however generate javascript that will check a certain
condition, for example
page << “if($F(‘foo’) == ‘bar’){”
page[:baz].hide()
page << “}”

I waffled about this at some length here:
http://www.spacevatican.org/2008/5/26/conditional-rjs-explained

Fred

Very close, thanks …
It seems to me that I can’t fetch or use what’s inside thevalue
attribute of the input field, it doesn’t return a string but a JavascriptElementProxythat doesn’t have a to_str/to_smethod.
I need to check if thatvalueis empty, and if not I need to use it
for the newvalue…
I will never be able to get out from this alone :stuck_out_tongue:

Any luck on getting the value? I am running into the same issue.

Thanks,
Greg

Hi,

Asd Asd wrote:

I have a problem with rjs. After submit the form, rjs not run. I would
like clear a text_field_tag. Here is my code:

Your code looks OK at first glance. Check to make sure you don’t have
another DOM element on the page with an id/name of ‘message’.

HTH,
Bill

Bill W. wrote:

Hi,

Asd Asd wrote:

I have a problem with rjs. After submit the form, rjs not run. I would
like clear a text_field_tag. Here is my code:

Your code looks OK at first glance. Check to make sure you don’t have
another DOM element on the page with an id/name of ‘message’.

HTH,
Bill

I haven’t other Dom element in page with an id/name of ‘message’.
It’s incredible.

darkhck

Hi everybody!

I have a problem with rjs. After submit the form, rjs not run. I would
like clear a text_field_tag. Here is my code:

–ActionController–
def add_post
@post = ChatPost.new(:ctext => params[:message])
@post.chat_room_id = session[‘selectedroomid’]
@post.lang = session[:locale]
@post.save
end

–View–
<% form_remote_tag :url => {:action => ‘add_post’} do %>
<%= text_field_tag “message”, “”, :size => 75%>
<%= submit_tag “Küldés” %>
<% end %>

–rjs - called: add_post.rjs–
page[‘message’].value = ‘’

I includ this:<%= javascript_include_tag :defaults %> in template.

I see in firebug that, the request is called and http status is 200, but
the field don’t clear.

Please help me.