0

I've got two areas with the same links, which I pick up with jquery and handle. The sidebar works fine, but the modal dialog does nothing. I don't have a ton of experience with jQuery, and I suspect my issue is there. The relevant html is as follows:

        <div id="sidebar"> 
            Case List:
            <br />
            <a id="add_case" href="#"> New </a>
            <ul>
                {%recursetree nodes %}
                <li>
                    <a class="get_case" data-id="{{node.id}}" href="#">{{node.name}}</a>
                    {%if not node.is_leaf_node %}
                        <ul class="children">
                            {{children}}
                        </ul>
                    {% endif %}
                    </li>
                {% endrecursetree %}
            </ul>
        </div>


    <div id="openFileTree" class="modalDialog">
        <div>
            <a href="#close" title="Close" class="close">X</a>
            <h2>Select:</h2>    
            <ul>
            {%recursetree nodes %}
            <li>
                <a class="get_case" data-id="{{node.id}}" href="#">{{node.name}}</a>
                {%if not node.is_leaf_node %}
                    <ul class="children">
                        {{children}}
                    </ul>
                {% endif %}
                </li>
            {% endrecursetree %}
            </ul>
        </div>
    </div>

And the relevant javascript is here:

$('.get_case').click(function(){
var id;
id = $(this).attr("data-id");
$.get('/CLP/case/', {caseId: id}, function(data){
    if(editor == undefined || editor.status == "destroyed")
    {
        $('#primary').html(data.value);
        $('#primary').attr('data-id', id);
    }
    else
    {
        $('#secondary').html(data.value);
        $('#secondary').attr('data-id', id);
    }
});
})

I feel like it's an oversight in scope or something, but I'm not sure what I messed up

SeanVDH
  • 866
  • 1
  • 10
  • 28
  • http://learn.jquery.com/events/event-delegation/ – Fresheyeball Dec 09 '14 at 21:16
  • Thanks- that's a great resource. Attaching to the list is definitely the cleaner way to do that. To clarify, though, the non-modal already works. The modal links simply have no effect. – SeanVDH Dec 09 '14 at 21:23
  • Is /CLP/case/ the correct path? Can you log that file and see if any GET variables is received? It seems `editor` is an undefined variable as well, should it be `data`? – anthonygore Dec 09 '14 at 21:24
  • I forgot to mention, the sidebar works. I've edited to include that. – SeanVDH Dec 09 '14 at 21:25
  • @Fresheyeball I see now what you were trying to say. The following question actually got me there, so I will attach it for future reference http://stackoverflow.com/questions/15083511/how-to-execute-jquery-inside-a-modal-window – SeanVDH Dec 09 '14 at 21:51

1 Answers1

0

How to execute jquery inside a Modal window?

The following was the correct format.

$(document).on("click", ".get_case", function(){...})

Community
  • 1
  • 1
SeanVDH
  • 866
  • 1
  • 10
  • 28