views:

413

answers:

2

i am trying to call a remote method to update page content via ajax/js. either i am too tired already or haml is not parsing the following code correctly to send the value of the query field via prototype. any ideas?

- form_remote_tag(:url => {:controller => "search", :action => "line"},:with => "'query=' + $('query').value" ) do
  %input{:type => 'text', :id => 'query'}
  %input{:type => 'submit', :value => 'Search'}

thanks a lot!

t

A: 

Have you tried a

= form_remote_tag

instead of

- form_remote_tag

I'm new to HAML myself but I was under the impression that you'll need the form tag to be actually generated not just executed...

Ganesh Shankar
`- form_remote_tag` works fine.
Jonathan Julian
@Jonathan Thanks! Duly noted...
Ganesh Shankar
`form_for` (and some other view helpers) adds the html straight into the buffer, so you don't need to insert it yourself using the `=`. If you do, you'll see two `<form>` tags.
Jonathan Julian
A: 

Try passing the :with as part of the options hash.

- form_remote_tag({ :url => {:controller => "search", :action => "line"}, :with => "'query=' + $('query').value" }) do

If that doesn't work, debug the problem: Look at the generated html. Is the text field with id query the only element in the page with that id? Is the js code correct? Use the Firebug console to ensure $('query').value returns whatever you've entered into the text field.

Still stuck? Add your generated html into your question so we can better help.

EDIT: Your query input tag does not have a name attribute. Without a name, the javascript helper code skips that field when serializing the form fields...also, you do not need the :with code.

%input{:type => 'text', :id => 'query', :name => 'query'}
Jonathan Julian
hello jonathan and thanks for your answer. the generated html seems to miss the "with" completely, see http://pastie.org/836556(this is the output with your suggested syntax) - i think that haml might be the problem... using haml (2.2.17)
hundi-hundi
and i just updated to haml 2.2.20 and the problem still resides...
hundi-hundi
The problem is not with Haml, it's with your input tag. See my edit.
Jonathan Julian
thanks a lot for your help. that indeed fixed my problem (of sending the parameter without the :with) but still i am wondering how to send a :with parameter with haml.
hundi-hundi
Haml is no different from erb when it comes to ruby code. Just pass the params as usual.In the case of `form_remote_tag`, have a look at the docs - it doesn't take `:with` as part of the options.
Jonathan Julian
thanks for the clarification. also thanks for your fast answers. much oblidged.
hundi-hundi