views:

231

answers:

1

Thanks in advanced.

So my overall goal is get a modal dialog box with a form in it to pop up. I am running into an issue when I click my link to bring up the modal it doesn't seem to be using javascript ... it just renders the page as if javascript is disabled. Code below :)

application.js

jQuery(function(){
$("#create_reminder_dialog").click(function() {
    $('#new_reminder_dialog').dialog('open');
});

// Initialzes Create Reminder Modal Box
$("#new_reminder_dialog").dialog({
    autoOpen: false,
    height: 350,
    width: 350,
    modal: true,
    buttons: {
        'Create New Reminder': function() {
            $('#new_reminder').submit();
        },
        Cancel: function() {
            $(this).dialog('close');
        }
    },
    close: function() {
            allFields.val('').removeClass('ui-state-error');
    }
});

});

My link in rails

<%= link_to "Create reminder", new_reminder_path, :id=>'create_reminder_dialog' %>

reminders/new.html.erb

<% form_for :reminder, :url => {:action => "create"}, :html=>{:id=>"new_reminder_dialog"} do |form| %>
<%= form.text_field :description, :class=>"short" %>
<%= form.label :description %>
<%= form.text_field :days, :class=>"short" %>
<%= form.label "Days between interactions" %>
<%= submit_tag "Submit" %><%end>

In firebug I'm not seeing a GET request like I expect.

Troubleshooting tips anyone??

A: 

I'm thinking you'd just need to return false in your click function to prevent the link's href from firing:

$("#create_reminder_dialog").click(function() {
    $('#new_reminder_dialog').dialog('open');
    return false;
});
Pat
Thanks ... that did the redirecting ... however I'm not seeing a GET request from clicking the link. Any ideas?
Ryan
You need to load the form in your #new_reminder_dialog <div> before calling dialog(): http://groups.google.com/group/jquery-ui/browse_thread/thread/11b86855abf54ce4
Pat
Yep ... that did it. Thanks Pat!
Ryan