On Wed, Dec 19, 2012 at 1:34 PM, Andriyko <ahryts...@gmail.com> wrote:

> Hello dear Django Users!
>
> I'm trying to use django inclusion_tag or/and assignment_tag with jquery
> 'onclick' event.
> Encountered such problems:
> 1. When using inclusion_tag/assignment_tag the content returned by them is
> rendered on page load, not onclick.
> And I suspect that it is correct behavior, once the tag is met it is
> rendered by template render. So, I think that should be some way to skip
> django tags? How?
>
> 2. With inclusion_tag the result returned by tag is shown in the place
> where it was called, not where it is 'intended' to be.
> And again, I think it is correct. But how to use inclusion_tag really
> onclick event?
> For example,
> -------------------
> <script>
>         $(function() {
>             var result = $("#select-result").empty();
>             $('#myid').somecontainer({animate:true,
>                 onClick: function(node){
>                    result.html('{% my_inclusion_tag "param1" "param2" %}');
>                 }
>             });
>         });
>     </script>
> -------------------
> As the result(in source of loaded page) I have content returned by
> inclusion_tag inside <script></script>, not under  #select-result div.
> Like
> ...
> onClick: function(node){
>                    result.html(<table>lalalala</table>);
>  }
> ...
>
> The code that works as expected :), onclick not onload.
>
> <script>
>         $(function() {
>             var result = $("#select-result").empty();
>             $('#myid').somecontainer({animate:true,
>                 onClick: function(node){
>                    alert(node.text);
>                 }
>             });
>         });
> </script>
>
>
> The tags are just a feature of the template language.  Their purpose is to
render the response that django will send to the browser.  There is no
automatic coupling to actions in the browser.  As you note, by the time
that the initial page load completes, the tags have finished all that they
are going to do.

I'm guessing that what you want calls for an AJAX scheme: You arrange for
click to produce an AJAX request (there is jquery support), which the
browser sends back to a specified (almost certainly different) url (but
probably on the same server/django).  Your urlconf must route this to a
view that recognizes the AJAX request, and returns data (xml, json, ...)
needed to define the content that you want to show, and returns it as a
response.  When this arrives back at the browser, a JavaScript function
that you have designated as the AJAX request's success callback is invoked
with access to the returned data.  This function must modify the DOM
according to the data.

Bill

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to