Last active
August 29, 2015 14:13
-
-
Save marcioj/ff722a3e0e7169a9597c to your computer and use it in GitHub Desktop.
Rerenders the result of an ajax request into the fancybox modal. Good for form redisplays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| = simple_form_for([@topic], remote: true, data: { "rerender-inside-modal" => true }) do |f| | |
| = f.input :name | |
| = f.input :content | |
| = f.submit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).on("ajax:complete", "form[data-rerender-inside-modal]", function(evt,xhr) { | |
| // make sure that server responded with a html content, otherwise ignore it | |
| if (xhr.getResponseHeader("Content-Type").indexOf("text/html") !== -1) { | |
| $.fancybox({ content: xhr.responseText }); | |
| } else { | |
| $.fancybox.close(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment