1

I am working in rails 2.3.8 and I got following rjs error in my rails application.

RJS error:
TypeError: $("#create_event_dialog") is nul

Then I click ok, then come another one.

Element.update("create_event", "<form action=\"/countries\" class=\"new_country\"   id=\"new_country\" method=\"post\" onsubmit=\"new Ajax.Request('/countries', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"authenticity_token\" type=\"hidden\" value=\"qWXCu2zMmlMhJG+GRf35kMbAIfzYAtFBee142ThmmMw=\" /></div>\n <p>\n    <label for=\"country_name\">Name</label><br />\n    <input id=\"country_name\" name=\"country[name]\" size=\"30\" type=\"text\" />\n  </p>\n  <p>\n    <input id=\"country_submit\" name=\"commit\" type=\"submit\" value=\"Create\" />\n  </p>\n</form>");
$('#create_event_dialog').dialog({
    title: 'New Event',
    modal: true,
    width: 500,
    close: function(event, ui) { $('#create_event_dialog').dialog('destroy') }

});

Here's my code...

<%= link_to_remote 'Add new countries', :url => {:controller => 'countries', :action => 'new'} %>

<div id = "create_event_dialog" style ="display:none;">
<div id = "create_event"></div>
</div>

new.js.rjs::

page.replace_html 'create_event', :partial => 'form'
page<< "$('#create_event_dialog').dialog({
    title: 'New Event',
    modal: true,
    width: 500,
    close: function(event, ui) { $('#create_event_dialog').dialog('destroy') }

});"

create.js.rjs

if @country
if @country.save

page<<"$('#create_event_dialog').dialog('destroy')"
else
page.alert @country.errors.full_messages(',').join("\n")
end
end

_form.html.erb

<%remote_form_for @country, :url => {:controller => 'countries', :action => 'create' } do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>

Can anybody help me? Why did I get this error?

Mchl
  • 61,444
  • 9
  • 118
  • 120
Rosh
  • 730
  • 2
  • 12
  • 32
  • Why should I get this error box? I created create_event div id in my application. There are no errors and **200** **ok** in firebug... How should I fix this? please help me to correct this. Is rjs not suitable for this? – Rosh Sep 22 '11 at 05:31
  • What is your prototype/jquery setup? Prototype is the default for rails 2 unless you've worked around that. `$('#create_event_dialog')` is a bad selector for prototype, it would be `$('create_event_dialog')` so you would see the null RJS error you're seeing with that. – jdeseno Nov 26 '11 at 15:43

0 Answers0