6

I want to display a modal window with an error message, when the user has entered something invalid in a form, but render another action if everything is OK. However, when I try to display the modal window with

render :js => "jQuery.facebox(#{...})"

only the actual JavaScript called is displayed:

try {
  jQuery.facebox(...)
} catch (e) { alert('RJS error:\n\n' + e.toString());
  alert('jQuery.facebox(\"<div class=\'error\'>Error</div>\")');
  throw e;
}
oxfist
  • 749
  • 6
  • 22
Hermine D.
  • 1,119
  • 3
  • 14
  • 19
  • The question is: What am I doing wrong? – Hermine D. May 17 '10 at 15:57
  • Make sure you have a failsafe incase you user doesn't have javascript. otherwise they wouldn't know they were getting an error. As a personal rule i find that removing modal windows increases usability...doesn't really help the question, though thought i would share some words of wisdom. – Schneems May 17 '10 at 22:04

3 Answers3

7

Have you tried putting the code in a partial? So instead of

render :js => "jQuery.facebox(#{...})"

try

render :partial => "my_facebox_popup" 

Then inside of your _my_facebox_popup.html.erb partial put your code:

<script type = "text/javascript">
...
</script>

debug any errors you get with firebug.

potashin
  • 44,205
  • 11
  • 83
  • 107
Schneems
  • 14,918
  • 9
  • 57
  • 84
1

Try this

 render :update do|page|
   page <<  "jQuery.facebox(#{...})"
 end
Salil
  • 46,566
  • 21
  • 122
  • 156
1

Maybe you should specify in the jQuery call the dataType of the response you're waiting for.

E.g.:

$.ajax({ 
  url: "/controller/action/id", 
  success: function(){
    $(this).addClass("done");
  },
  dataType: 'script' 
});
Stan Bright
  • 1,355
  • 1
  • 15
  • 22