andy_bu
andy_bu

Reputation: 123

Django checkbox display content

I try to display different content. But something i make false. If i check pid it must show only pid's, if i check pid and title it must show both. In my example i show both, but how i can change it with checkboxes? Thanks.

<form class="fedora" method="post">{% csrf_token %}
    <input type="checkbox"  name="pid" value="{{obj.pid}}"> pid
    <input type="checkbox" checked name="title" value="{{obj.title}}"> title
</form>

...

{% fedora_access %}
        <p><a href="{% url 'display' obj.pid %}"> 
        {%if  obj.pid %} {{ obj.pid }}|{% endif %}          
        {{ obj.pid }} | {{ obj.title }}  
        </a></p>  
{% end_fedora_access %}

Upvotes: 1

Views: 1542

Answers (1)

000
000

Reputation: 27247

<form class="fedora" method="post">{% csrf_token %}
    <input type="checkbox" id="show_pid"  name="pid" value="{{obj.pid}}"> pid
    <input type="checkbox" id="show_title" checked name="title" value="{{obj.title}}"> title
</form>

...

{% fedora_access %}
        <p><a href="{% url 'display' obj.pid %}">      
        <span class="show_pid">{{ obj.pid }}</span> | <span class="show_title">{{ obj.title }}</span>
        </a></p>  
{% end_fedora_access %}

Then in javascript:

$(function() {
    $('#show_pid').click(function() {
        if ($(this).is(':checked')) $('.show_pid').show();
        else                        $('.show_pid').hide();
    });
    $('#show_title').click(function() {
        if ($(this).is(':checked')) $('.show_title').show();
        else                        $('.show_title').hide();
    });
});

although, when neither are checked, you'll have | still showing. You can fake that with css. Give the spans a border-left: 1px solid black and a border-right: 1px solid black or something.

Upvotes: 1

Related Questions