Hi again, 

So I followed the documentation and created a formset as we have there. 
https://docs.djangoproject.com/en/1.6/topics/forms/formsets/

Then I followed the documentation and included the django-formset-js:
https://pypi.python.org/pypi/django-formset-js/

But I can't get the buttons "Add another" neither "Delete" working.  
And I'm sure I'm missing something that I don't know yet.  

This is what I have so far: 


*forms.py*

from django import forms
from django.forms.formsets import formset_factory

class ArticleForm(forms.Form):
    title = forms.CharField()
    pub_date = forms.DateField()


*views.py*

from django.forms.formsets import formset_factory
from django.shortcuts import render_to_response
from formsets.djdocs.forms import ArticleForm

def manage_articles(request):
    ArticleFormSet = formset_factory(ArticleForm, can_delete=True, extra=2)
    if request.method == 'POST':
        formset = ArticleFormSet(request.POST, request.FILES)
        if formset.is_valid():
            # do something with the formset.cleaned_data
            for form in formset:
                print(form.as_table())
            pass
    else:
        formset = ArticleFormSet()
        
    return render_to_response('djdocs/manage_articles.html', {'formset': 
formset})


*urls.py*

from django.conf.urls import patterns, include, url
from formsets.djdocs.views import manage_articles

urlpatterns = patterns('djdocs.views',
    url(r'^$', manage_articles),
)


*template manage_articles.html*

{% extends "index.html" %}
{% block content %}

{% load formset_tags %}
<div id="formset" data-formset-prefix="{{ formset.prefix }}">
    {{ formset.management_form }}

    <div data-formset-body>
        <!-- New forms will be inserted in here -->
        {% for form in formset %}
            <div data-formset-form>
                {{ form }}
<div class="hidden">{{ form.DELETE }}</div>
                <button type="button" data-formset-delete-button>Delete 
form</button>
            </div>
        {% endfor %}
    </div>

    <!-- The empty form template. By wrapping this in a <script> tag, the
    __prefix__ placeholder can easily be replaced in both attributes and
    any scripts -->
    <script type="form-template" data-formset-empty-form>
        {% escapescript %}
            <div data-formset-form>
                {{ formset.empty_form }}
                <button type="button" data-formset-delete-button>Delete 
form</button>
            </div>
        {% endescapescript %}
    </script>

    <!-- This button will add a new form when clicked -->
    <input type="button" value="Add another" data-formset-add>

    <script>jQuery(function($) {
        $("#formset").formset({
            animateForms: true
        });
    });</script>

</div>

{% endblock %}

In the index.html file I'm loading the .js like:

{% load staticfiles %}
<script src="{% static "js/jquery.js" %}"></script>
<script src="{% static "js/jquery.formset.js" %}"></script>


Any advice? :)

Best regards, 

Leandro



On Wednesday, April 9, 2014 7:19:11 AM UTC+2, Venkatraman.S. wrote:
>
> Actually, there is nothing more to it. Include the js and create the 
> formset_factory and start using it in the template by iterating over it. In 
> the view, post-POST, again iterate over the formsets. Bulk of the work is 
> done by the js and you dont have to do much in django. There is a minor bug 
> in the js which lets even one row in the UI to get deleted, but its not a 
> show-stopper :)
>
> Let me know if its still trouble and I shall write something up.
>
> On Tue, Apr 8, 2014 at 10:16 PM, Leandro Alves <[email protected]<javascript:>
> > wrote:
>
>> Hello Venkatraman,
>>
>> Yes.. I saw this one was well... and I want to try it.. but I'm still 
>> learning about Formsets...
>> Would you have any basic simple foo example to share? :)
>>
>> Best, 
>>
>> Leandro
>>
>>
>>
>> On Tuesday, April 8, 2014 2:48:15 AM UTC+2, Venkatraman.S. wrote:
>>
>>> Have you tried the jquery formset - works like a breeze for me. 
>>>
>>>
>>> On Mon, Apr 7, 2014 at 10:43 PM, Leandro Alves <[email protected]> wrote:
>>>
>>>>  Hi, 
>>>>
>>>> I wonder if anyone knows of any example of django-dynamic-formsets [1] 
>>>> that works with Django 1.6?
>>>>
>>>> So far all I found on the internet are over 3 years old and they don't 
>>>> work with Django version 1.6. 
>>>>
>>>> I am willing to pay for any example that works if necessary. :)
>>>>
>>>> Thanks in advance, 
>>>>
>>>> Leandro
>>>>
>>>>
>>>> [1] - https://code.google.com/p/django-dynamic-formset/
>>>>  
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>>
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/django-users/95dc89cb-cdd7-43c5-adca-da0a1aaf9573%
>>>> 40googlegroups.com<https://groups.google.com/d/msgid/django-users/95dc89cb-cdd7-43c5-adca-da0a1aaf9573%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5784f512-3a99-419e-8e06-1bfe5ef1ba55%40googlegroups.com<https://groups.google.com/d/msgid/django-users/5784f512-3a99-419e-8e06-1bfe5ef1ba55%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f06acb23-294a-4ed9-9919-5ed11ec5c503%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to